Kubotek Forum

KeyCreator & KeyCreator Viewer Technical discussion of CAD/CAM and integrated partner products
Kubotek Forum > KeyCreator & KeyCreator Viewer > Set the options for exporting PDF View modes: 
User avatar
Advanced member
Advanced member
Soli - 7/23/2020 10:48:34 AM
   
RE:Set the options for exporting PDF
Hans,

Looks like we're back to the old days of the old forum
Only then did someone receive such support.
Too bad it's been canceled.
Becuase of  this bug, I give up.
But I can do something to set the options before I sent the drawing to PDF.

Thanks.

Solomon Steinberg,
Israel

DELL OPTIPLEX 7050
NVIDIA QUADRO P2000
KEYCREATOR 13.5
KEYCREATOR 2020 SP2



User avatar
Advanced member
Advanced member
John McCullough - 7/23/2020 12:21:41 PM
   
RE:Set the options for exporting PDF
I'm glad to see you guys having a good discussion here. Sorry to see that there is a bug blocking progress. 

Did you submit the bug? If not, you may want to check out the new Request feature in your support account (I just published a blog article about it today). This will track the status of your request and help us automate communication when a related bug fix is released. 
John Wright McCullough
GM Marketing, Kubotek3D

User avatar
Advanced member
Advanced member
Hans_Winkler - 7/23/2020 1:08:06 PM
   
RE:Set the options for exporting PDF
John,
I submitted this bug.
I think that request feature will be a great tool!

Thank you,
Hans

User avatar
Advanced member
Advanced member
Dana - 7/31/2020 5:30:10 AM
   
RE:Set the options for exporting PDF
Soli wrote:

Hans and Dana,

Your help is highly appreciated.

All set functions work very well.
But ExportEntities aGenSelEnts , PDF , "TEST.PDF" produces
an additional unwanted
view 1 of the model at x=0 y=0 of the drawing.

(for both All display or Window selection method )

 

Other problem.

The line thickness is very thin and is not related to the width scale in the setting configuration.

I have to try harder.

Thank you.




I never tried ExportEntities aGenSelEnts , PDF, but I don't ever recall seeing the extra model view with EXPORT PDF, but due to the line width issue I haven't used it in some time.  The Autoit script to drive it through the menus solves that, and does some additional interfacing with our PDM system.  The line of Autoit code I posted above is part of a larger routine that retrieves the layout name and description, and uses that information to populate an item card in the PDM system, then attaches the PDF to it.



User avatar
Advanced member
Advanced member
Hans_Winkler - 8/3/2020 11:04:59 AM
   
RE:Set the options for exporting PDF
Hi Dana,

Dana wrote:
The Autoit script to drive it through the menus solves that, and does some additional interfacing with our PDM system.  The line of Autoit code I posted above is part of a larger routine that retrieves the layout name and description,


Would you be willing to share some more of that Autoit code, as it pertains to the PDF export (Save As) dialog box? When a saved CKD file is exported to PDF, it automatically fills in the CKD filename into the file name combo box and highlights that text. When that is the case I'm unable to set that text.
Thank you,
Hans

User avatar
Advanced member
Advanced member
Dana - 8/4/2020 8:09:19 AM
   
RE:Set the options for exporting PDF
Hans_Winkler wrote: Hi Dana,

Would you be willing to share some more of that Autoit code, as it pertains to the PDF export (Save As) dialog box? When a saved CKD file is exported to PDF, it automatically fills in the CKD filename into the file name combo box and highlights that text. When that is the case I'm unable to set that text.
Thank you,
Hans


It's actually a combination of kxl and autoit.  The kxl is very simple, it sets the pdf parameters and then gets some information and then runs the compiled autoit executable, passing the layout name (which I use for part number) and description to the executable on the command line:

SET PDFHeight, 11
SET PDFWidth, 17
SET PDFResolution, 600
//Set PDFMarginTop,         0.0
//Set PDFMarginBottom,      0.0
//Set PDFMarginLeft,        0.0
//Set PDFMarginRight,       0.0
Set PDFScale,             0.0
Set PDFBlack,  1
Set PDFPrintConfig, "gadget"

GetLayout , hlay // get the current layout handle
GetLayoutNames hlay, $lname, $ldesc  // get the layout name and description

SPRINT $execmd, "kxl\\custom\\kc2st.exe \"%s\" \"%s\"", $lname[0], $ldesc[0]
exec $execmd

Note those "Set PDFMargin" lines are commented out as I didn't need them but saved for future reference.

The autoit routine waits for the Keycreator "external process" window and sends a bunch of escapes to KC:

WinWaitActive("External Process")
Send("{ESC}{ESC}{ESC}{ESC}")

WinWaitActive("KeyCreator")

Sleep(250)

$layname = $CmdLine[1]
$laydesc = $CmdLine[2]

Then there's a bunch of stuff related to our PDM system, then (note I'm using the classic menu so I'm sending Fkeys, the sent keystrokes would be different otherwise):

Send("{ESC}{ESC}{ESC}{F6}{F3}{F5}") ; escape to root and autoscale
Sleep(250)

;start pdf export dialog, select all disp-all
;Sleep(500)
While 1
    Send("{ESC}{ESC}{ESC}{ESC}{ALT}FEF{F7}{F1}")
    Sleep(500)
    ; next line catches missed {ALT} keystroke when a fillet dialog comes up instead, and retries since it only seems to happen once, no idea why
    If Not (WinExists("Constant Radius Edge Blend") Or WinExists("KeyCreator", "Enter radius")) Then ExitLoop
    Sleep(500)
WEnd

If WinExists("KeyCreator", "Choose ADDITION method or select an entity") Then
    Send("{ENTER}")
EndIf
WinWaitActive("Save As")
ControlSetText("Save As", "", 1148, $smwork) ; set to S: drive
Sleep(500)
;MsgBox(4096, "debug", "check path")
ControlClick("Save As", "", "Button2")
Sleep(500)
ControlSetText("Save As", "", 1148, $layname & ".pdf")
ControlClick("Save As", "", "Button2")
BlockInput(0)
WinWaitClose("Save As")
Sleep(1000)

;wait until the export process is finished
While (_FileInUse($smwork & $layname & ".pdf"))
    Sleep(500)
WEnd

Then there's more unrelated stuff, and finally I display the pdf for a half second just to verify that it got created:

;Open the pdf file in Acrobat
ShellExecute($smwork & $layname & ".pdf")
WinWait($layname & ".pdf")
WinActivate($layname & ".pdf")
WinWaitActive($layname & ".pdf", "")
Sleep(500)
Send("^w") ; close the pdf file

WinActivate("KeyCreator", "")


I think that's everything related to the pdf export.  If anybody really cares the entire autoit script follows:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=2.0.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


AutoItSetOption("SendCapslockMode", 0) ; default is 1 and then script won't work ir capslock is on, dunno why
Opt("TrayIconDebug", 1)
Opt("SendKeyDelay", 20)
Opt("sendkeydowndelay", 20)
$UseIndexPN = 0
$printopt = RegRead("HKEY_CURRENT_USER\Software\Danaware\KC2ST", "printopt")
If @error <> 0 Then
    $printopt = 1
    RegWrite("HKEY_CURRENT_USER\Software\Danaware\KC2ST", "printopt", "REG_DWORD", $printopt)
EndIf

If Not WinExists("ENOVIA SmarTeam") Then
    $noSmarTeam = 1
Else
    $noSmarTeam = 0
    ;MsgBox(16 + 4096, "SmarTeam not running", "Error:  SmarTeam must be running and in a document folder" & @CRLF & "Please start SmarTeam and retry.")
    ; no longer exit, routine can be used to export pdfs even without ST running
    ;Exit
EndIf

$smwork = "S:\"

;$ret = WinActivate("Kubotek KeyCreator")
$ret = WinActivate("External Process")

WinWaitActive("External Process")
Send("{ESC}{ESC}{ESC}{ESC}")

WinWaitActive("KeyCreator")

#cs getting from the kxl now on the command line
    ; Get current layout name (number) and description from the layout dialog
    BlockInput(1)
    Send("{ESC}{ESC}{ESC}{ESC}{F3}{F6}{F1}") ; classic menu detail, layout, control
    WinWait("Drawing Layout Control")
    Sleep(250)
    $layname = ControlGetText("Drawing Layout Control", "", 1298) ; layout name is part number
    $laydesc = ControlGetText("Drawing Layout Control", "", 1390)
    ControlClick("Drawing Layout Control", "", 2)
    WinWaitClose("Drawing Layout Control")
    Sleep(250)
    Sleep(1000)
    BlockInput(0)
#ce

; Send("{ESC}{ESC}{ESC}{F6}{F3}{F5}") ; escape to root and autoscale
Sleep(250)


$layname = $CmdLine[1]
$laydesc = $CmdLine[2]
$noAS = 0

ConsoleWrite($layname & "  " & $laydesc & @CRLF)

#Region ### START Koda GUI section ### Form=C:\KeyCreator64.10.0\KXL\Custom\KC2ST1.kxf
$Form1 = GUICreate("KeyCreator - SmarTeam Integration", 458, 288, -1, -1, -1, $WS_EX_TOPMOST)
GUISetFont(12, 400, 0, "MS Sans Serif")
$CheckPrint = GUICtrlCreateCheckbox("Print Drawing", 8, 152, 121, 25)
If ($printopt = 1) Then
    GUICtrlSetState($CheckPrint, $GUI_CHECKED)
Else
    GUICtrlSetState($CheckPrint, $GUI_UNCHECKED)
EndIf
$checkNoAS = GUICtrlCreateCheckbox("Don't Autoscale", 200, 152, 201, 25)
$CheckCard = GUICtrlCreateCheckbox("Create SmarTeam card", 8, 192, 201, 25)
$Label4 = GUICtrlCreateLabel("(Please verify target SmarTeam folder is highlighted)", 24, 216, 370, 24)
$CheckUseIndexPN = GUICtrlCreateCheckbox("Use ST Index number for PN", 225, 192)
If FileExists(($smwork & $layname & ".pdf")) Then
    GUICtrlSetState($CheckCard, $GUI_UNCHECKED)
    $cardopt = 0
Else
    GUICtrlSetState($CheckCard, $GUI_CHECKED)
    $cardopt = 1
EndIf
GUICtrlSetState($CheckUseIndexPN, $GUI_UNCHECKED)

If $noSmarTeam Then
    GUICtrlSetState($CheckCard, $GUI_UNCHECKED)
    GUICtrlSetState($CheckCard, $GUI_DISABLE)
    GUICtrlSetState($Label4, $GUI_DISABLE)
    $cardopt = 0
EndIf
$OKButton = GUICtrlCreateButton("OK", 24, 248, 75, 25, $WS_GROUP)
$CancelButton = GUICtrlCreateButton("Cancel", 360, 248, 75, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Part Number:", 8, 72, 97, 24)
$Label2 = GUICtrlCreateLabel("Description:", 8, 112, 88, 24)
$Label3 = GUICtrlCreateLabel("Export Drawing to SmarTeam", 16, 8, 427, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$Inname = GUICtrlCreateInput($layname, 104, 72, 337, 24)
$Indesc = GUICtrlCreateInput($laydesc, 104, 112, 337, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

If Not $noSmarTeam Then WinActivate("ENOVIA SmarTeam")
WinActivate("KeyCreator - SmarTeam Integration")
GUICtrlSetState($OKButton, $GUI_FOCUS)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            WinActivate("KeyCreator")
            Exit
        Case $CancelButton
            WinActivate("KeyCreator")
            Exit
        Case $OKButton
            GUIDelete($Form1)
            ExitLoop
        Case $Inname
            $layname = GUICtrlRead($Inname)
        Case $Indesc
            $laydesc = GUICtrlRead($Indesc)
        Case $CheckPrint
            $printopt = (GUICtrlRead($CheckPrint) == $GUI_CHECKED)
            ;MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$printopt' & @CRLF & @CRLF & 'Return:' & @CRLF & $printopt) ;### Debug MSGBOX
            RegWrite("HKEY_CURRENT_USER\Software\Danaware\KC2ST", "printopt", "REG_DWORD", $printopt)
        Case $CheckCard
            $cardopt = (GUICtrlRead($CheckCard) == $GUI_CHECKED)
            If ($cardopt = 0) Then
                GUICtrlSetState($CheckUseIndexPN, $GUI_DISABLE)
                WinActivate("KeyCreator")
                WinActivate("KeyCreator - SmarTeam Integration")
                GUICtrlSetState($Label4, $GUI_HIDE)
            Else
                GUICtrlSetState($CheckUseIndexPN, $GUI_ENABLE)
                WinActivate("ENOVIA SmarTeam")
                WinActivate("KeyCreator - SmarTeam Integration")
                GUICtrlSetState($Label4, $GUI_SHOW)
            EndIf
        Case $CheckUseIndexPN
            $UseIndexPN = (GUICtrlRead($CheckUseIndexPN) == $GUI_CHECKED)
        Case $checkNoAS
            $noAS = (GUICtrlRead($checkNoAS) == $GUI_CHECKED)
    EndSwitch
WEnd

If $cardopt Then ; create the profile card
    WinActivate("ENOVIA SmarTeam")
    WinWaitActive("ENOVIA SmarTeam")
    Sleep(100)
    ;ConsoleWrite("ready to run SmarTeam menus" & @CRLF)
    ;ConsoleWrite("return" & ControlFocus("ENOVIA SmarTeam", "", "[CLASS:TAdvToolBar; INSTANCE:1]"))
    ;ControlSend("ENOVIA SmarTeam", "", 200996, "!AACKK") ; for reasons unknown this seemed to work intermittently
    ;ControlSend("ENOVIA SmarTeam", "", "[CLASS:TAdvToolBar; INSTANCE:1]", "!aackk") ; trying the classname instead of numeric id which seems to change?
    ;ControlClick("ENOVIA SmarTeam", "", "[CLASS:TAdvToolBar; INSTANCE:1]", "left", 1, 77, 12)
    ;Send("!aackk")
    If Not ControlSend("ENOVIA SmarTeam", "", "[CLASS:TAdvToolBar; INSTANCE:1]", "!AACKK") Then ; sometimes the menu doesn't respond to keystrokes
        ConsoleWrite("ControlSend failed")
        ControlClick("ENOVIA SmarTeam", "", "[CLASS:TAdvToolBar; INSTANCE:1]", "main", 1, 77, 12)
        ControlSend("ENOVIA SmarTeam", "", "[CLASS:TAdvToolBar; INSTANCE:1]", "ACKK")
        MsgBox(4096, "debug", "ControlSend failed, using alternate")
    EndIf

    ;Sleep(1000)
    ;MsgBox(4096, "debug", "keystrokes sent to smarteam menus", 2)
    WinWait("ENOVIA SmarTeam", "KeyCreator Drawing") ; new card created but not filled out yet

    If $UseIndexPN Then
        $oldlayname = $layname
        $layname = ControlGetText("ENOVIA SmarTeam", "", "TNewMaskEdit1")
        ;MsgBox(4096, "debug", "layout name = " & $layname)
        WinActivate("KeyCreator")
        WinWaitActive("KeyCreator")
        Send("{ESC}{ESC}{ESC}{ESC}{F3}{F6}{F1}") ; classic menu detail, layout, control
        WinWait("Drawing Layout Control")
        Sleep(250)
        ControlClick("Drawing Layout Control", "", 1604)
        WinWaitActive("Enter new name for layout")
        ControlSetText("Enter new name for layout", "", 1037, $layname)
        ControlClick("Drawing Layout Control", "", 1)
        WinWaitClose("Enter new name for layout")
        WinWaitClose("Drawing Layout Control")
        ;Send("{ESC}{ESC}{ESC}{ESC}{F3}{F6}{F8}{F8}") ; classic menu detail, layout, toggle, toggle (to refresh title block information with new PN)
        Send("{ESC}{ESC}{ESC}{ESC}{ALT}DNP") ; Detail-Note-Update fields
        Sleep(250)
        Send("{ESC}{F6}{F3}{F5}") ; escape to root and autoscale
        Sleep(1000)
    EndIf
EndIf

; Export PDF regardless of $cardopt
; have to do this first because SmarTeam expects the pdf to exist when that field in the card is filled in
WinActivate("KeyCreator")
WinWaitActive("KeyCreator")

If Not $noAS Then
    Send("{ESC}{ESC}{ESC}{F6}{F3}{F5}") ; escape to root and autoscale
    Sleep(250)
EndIf

 

If $cardopt Then ; continue filling out the card
    WinActivate("ENOVIA SmarTeam")
    WinActivate("ENOVIA SmarTeam")
    ;WinWaitActive("ENOVIA SmarTeam")
    While ControlSetText("ENOVIA SmarTeam", "", "TNewMaskEdit5", $layname) <> 1
    WEnd
    While ControlSetText("ENOVIA SmarTeam", "", "TNewMaskEdit2", $laydesc) <> 1
    WEnd
    ControlClick("ENOVIA SmarTeam", "", "TAdvGlowButton39")
    ControlSend("ENOVIA SmarTeam", "", "TAdvGlowButton39", "e") ; go to details tab
    Sleep(1000)
    While ControlSetText("ENOVIA SmarTeam", "", "TFBEdit1", $layname & ".pdf") <> 1
    WEnd
    ;MsgBox(4096, "debug", "got here")
    While ControlSetText("ENOVIA SmarTeam", "", "TVaultBEdit1", $smwork) <> 1
    WEnd
    Sleep(250)
    ConsoleWrite("wrote text to smarteam" & @CRLF)
    ControlClick("ENOVIA SmarTeam", "", "TAdvGlowButton40") ; click OK
    WinWaitActive("SmarTeam", "Link")
    ControlClick("SmarTeam", "Link", "TAdvGlowButton4")
EndIf

;Open the pdf file in Acrobat
ShellExecute($smwork & $layname & ".pdf")
WinWait($layname & ".pdf")
WinActivate($layname & ".pdf")
WinWaitActive($layname & ".pdf", "")

If $printopt Then
    ;MsgBox(4096, "debug", "got here")
    Send("!fp")
    WinWaitActive("Print")
    ; not clicking in the "Print" window, allow the user to select the printer settings
    WinWaitActive("Progress")
    While WinExists("Progress")
        Sleep(100)
    WEnd
    Sleep(500)
Else
    Sleep(1000) ; wait long enough for user to see the file
EndIf

WinActivate($layname & ".pdf")
WinWaitActive($layname & ".pdf")
Sleep(500)
Send("^w") ; close the pdf file

WinActivate("KeyCreator", "")

Exit

Func _FileInUse($sFilename)
    Local $aRet, $hFile
    $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _
            "str", $sFilename, _ ;lpFileName
            "dword", 0x80000000, _ ;dwDesiredAccess = GENERIC_READ
            "dword", 0, _ ;dwShareMode = DO NOT SHARE
            "dword", 0, _ ;lpSecurityAttributes = NULL
            "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING
            "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
            "hwnd", 0) ;hTemplateFile = NULL
    $hFile = $aRet[0]
    If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1
        $aRet = DllCall("Kernel32.dll", "int", "GetLastError")
        SetError($aRet[0])
        Return 1
    Else
        ;close file handle
        DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
        Return 0
    EndIf
EndFunc   ;==>_FileInUse




User avatar
Advanced member
Advanced member
Hans_Winkler - 8/4/2020 10:36:25 AM
   
RE:Set the options for exporting PDF
Hi Dana,
thank you very much. I have used Autoit in the past mainly writing scripts to help me out in different situations. I have had trouble stepping through windows that exist. A friend of mine helped me out and made me aware that setting the appropriate “Sleep” time is important for the scripts to work.
Thank you again,
Hans

User avatar
Advanced member
Advanced member
Hans_Winkler - 8/4/2020 10:47:10 AM
   
RE:Set the options for exporting PDF
Dana,
BTW, passing the layout name and description to the executable on the command line,
that is really slick. Didn't know I could do that!
Thank you, Hans


User avatar
Advanced member
Advanced member
Dana - 8/6/2020 11:18:07 AM
   
RE:Set the options for exporting PDF
Yes, using the sleep command is important.  The Autoit Window Info tool is also valuable to find the actual ID of dialogs and controls.  Interacting directly with a control is much more reliable than sending keystrokes to what you hope is in focus.

1 2
Login