Creo Elements/Direct Modeling and other applications can communicate using DDE (Dynamic Data Exchange). DDE is a standard Windows method for interprocess communication. It allows applications implementing macro languages to call each other's macro commands. DDE calls can be implemented in various programming languages like Visual Basic or C++.
Creo Elements/Direct Modeling Lisp commands can be executed easily from any DDE client application by passing the Lisp command with a DDE call. Vice versa, Creo Elements/Direct Modeling can call any other application (which implements a DDE server) by using built-in Lisp commands.
The following sections describe the communication in either direction by using example code. The actual function names used to implement a DDE connection are heavily language dependent. The examples in this document use the Visual Basic command syntax because it is easy to understand and not covered with too much overhead. The MSDN article "Implementing DDE Using C++ Classes" provides examples on how to implement a DDE client in C++.
Creo Elements/Direct Modeling implements a DDE server that allows the caller to connect to Creo Elements/Direct Modeling and execute any Lisp command as if it had been entered in Creo Elements/Direct Modeling's user input line.
To connect to a DDE server, the client needs two keys: the service name and the topic name. The service name identifies the DDE server. For Creo Elements/Direct Modeling, the service name is "PESD"; for Creo Elements/Direct 3D Access, the name is "SD_ACCESS". The topic name is an application-specific string and must be understood by the DDE Server. Creo Elements/Direct Modeling understands one topic name by default which lets the client execute commands in Creo Elements/Direct Modeling. This topic name is "GENERAL".
Both the service name and topic name must be supplied when establishing a DDE connection to Creo Elements/Direct Modeling. This is done by:
nChannelNumber = DDEInitiate("PESD", "GENERAL")
DDEInitiate returns a channel number which has to be used in further calls to Creo Elements/Direct Modeling. These calls are done using the DDEExecute command.
The following example loads a 3D model into Creo Elements/Direct Modeling:
bSuccess = DDEExecute(nChannelNumber, "(load_package ""d:/users/SDUser/Model.pkg"")")
The command string (second parameter) is an arbitrary Lisp command understood by Creo Elements/Direct Modeling. The additional double quotes in the example are only used to mask the quotes. The actual command executed in Creo Elements/Direct Modeling is:
(load_package "d:/users/SDUser/Model.pkg")
It is also possible to request variable values from Creo Elements/Direct Modeling using DDE. This is done using the DDERequest command.
Let's assume the variable myVariable has been set to a string as follows:
DDEExecute(nChannelNumber, "(setf myLispVariable ""My Value"")")
Here's how an external program could inquire the variable value from MODELING_NAME:
myVariable = DDERequest(nChannelNumber, "myLispVariable")
MyVariable will hold the value "My Value" after this call.
DDEInitiate, DDEExecute and DDERequest are the most frequently-used DDE commands needed for Creo Elements/Direct Modeling communication.
The client has to ensure that resources are returned to the system when the connection is no longer needed by explicitly terminating the connection:
DDETerminate(nChannelNumber, "PESD")
All necessary DDE commands needed to call an external DDE server are available as IKIT APIs.
The application called from Creo Elements/Direct Modeling must implement a DDE server and should be able to interpret and handle command strings passed by DDEExecute. The usual design approach is that the commands are written in a macro language which is interpreted by the external application.
A detailed description of all Creo Elements/Direct Modeling DDE-specific Lisp functions follows.
Starting with CoCreate OneSpace Modeling 2007, Creo Elements/Direct Modeling registers as a Unicode DDE server and client. This can have subtle implications for old non-Unicode DDE clients which made assumptions about the encoding used for strings sent in DDE messages.
Any data sent to other applications via DDE are encoded in UTF-16. If the other application registers as a non-Unicode DDE server or client, the operating system will perform an automatic string conversion from UTF-16 encoding to the encoding which corresponds to the system's codepage. The default system codepage for Western European or US systems is CP1252, which is a variant of ISO8859-1; when running on a Japanese version of Windows, the system defaults to codepage CP932, which is a variant of Shift-JIS encoding.
DDE integrations with versions of Creo Elements/Direct Modeling preceding CoCreate OneSpace Modeling 2007 may need to be reviewed for proper handling of encodings, in particular if umlauts or accented characters are sent over the DDE communication mechanism.
(sd-dde-enable on-off)
(sd-dde-enable :on)
(sd-dde-initiate servicename topicname)
(setq handle (sd-dde-initiate "Server1" "Topic1"))
(sd-dde-execute handle command)
(setq result (sd-dde-execute handle "DoIt"))
(sd-dde-poke handle item data)
(setq result (sd-dde-poke handle "R1C1" "42"))
(sd-dde-request handle item)
(setq status (sd-dde-request handle "StatusVar"))
(sd-dde-advise handle item on-off handlerfunction)
(setf ddehandle (sd-dde-initiate "Excel" "[Book1]Sheet1")) (defun ddeadvisehandler(args) (let ((item (second args)) (hconv (first args))) (when (and (string= item "r1c1") (equal ddehandle hconv)) (format t "Item ~S was updated - new value is ~S~%" item (third args))))) (sd-dde-advise ddehandle "r1c1" :on 'advisehandler) ... (sd-dde-advise ddehandle "r1c1" :off 'advisehandler)
(sd-dde-add-topic topic-name)
(setq result (sd-dde-add-topic "New Topic"))
(sd-dde-remove-topic topic-name)
(setq result (sd-dde-remove-topic "New Topic"))
(sd-dde-close handle)
(sd-dde-close handle)
(sd-dde-request-timeout timeout)
(sd-dde-execute-timeout timeout)
© 2024 Parametric
Technology GmbH (a subsidiary of PTC Inc.), All Rights Reserved |