TSL | Lisp Scriptinseret

Customising your work environment for TSL, this information is useful for creating a ribbon, tool palette or toolbar

Solution:

The lisp interface for Tsl consists of two commands: "Hsb_ScriptInsert" and "Hsb_ScriptInsertNoPrompt".

The lisp command "Hsb_ScriptInsert" can be used to customize a toolbar. When executing the autocad command 

(Hsb_ScriptInsert "aa" 0 "key")

(Hsb_ScriptInsert "aa" )

(Hsb_ScriptInsert "aa" "key")

(Hsb_ScriptInsert "aa" 0)

an instance of the TSL named "aa" is added with the option 0. The option 0 means multiple instances can be inserted. If the option is 1, only one instance will be inserted at a time. The 0/1 is optional.

The second string value in the argument list is recognized and will be send to the script as _kExecuteKey. The "key" is optional.

If the script named "aa" does not exist at that time, an attempt is made to load the script from the file system. If the complete file path was specified as argument, that file will be loaded. If not found, the install folders of hsbCAD are searched. Then the Company/Tsl folder is searched, including its sub folders. 

The tsl script will be inserted with _bOnInsert set to TRUE.

The following are examples of the "Hsb_ScriptInsertNoPrompt". During this insert, the value of _bOnInsert is set to FALSE since all data are already specified.

When the MAP, or MAPMM key is specified, the contents will be interpreted and inserted into the _Map variable. The MAP (MAPMM) value is a ';'-separated list. The keys and values are alternating. If you want to add a ';' character in the value, it needs to be escaped by the '\' escape character. Also the '\' character needs to be escaped. The list can be closed with a ';', but this is optional. So far for interpreting the ';'-separated string. Of course Lisp has itself its escape sequences when the string is literal, so the instruction could look like (cons "MAP" "BC;this \\; is embedded")

You can also use the keyword "NAME" as an alias for "SCRIPTNAME", and the keyword "ARGUMENT" for the keyword "MAPMM".

The following are recognized keys in the list of key value couples passed as argument to the Hsb_ScriptInsertNoPrompt lisp command:

SCRIPTNAME or NAME * required; only 1 allowed; name of the script as string.

20ELEMID * optional; can appear many times; the value must be of ent type; the value will be appended to the _Entity array, and if the value is of the correct type it will populate the _Element, _Opening, _Viewport,... array. The value could be a variable ent1, eg set by(setq ent1 (entlast)).

20BEAMID * optional; can appear many times; the value must be of GenBeam type (Beam, Sheet, Sip); the value will be appended to the _GenBeam array, and if the value is of the correct type it will populate the _Beam, _Sheet or _Sip array. The value could be a variable bm1, eg set by(setq bm1 (entlast)).

11PT * optional; can appear many times; the value must be a Point type, specified in world coordinate system (WCS). For the E, O, and S types the first key value will become _Pt0. All other values are appended to the _PtG array. If you have a point in UCS, you can transform it into WCS using (trans pt 1 0).

13UCSX * optional; only 1 allowed; the value must be a vector in WCS. The value will return in the Tsl as _XU. If not specified, the current ucs x value will be used. It could also be the specified by (getvar "UCSXDIR").

13UCSY * optional; only 1 allowed; the value must be a vector in WCS. The value will return in the Tsl as _YU. If not specified, the current ucs y value will be used. It could also be the specified by (getvar "UCSYDIR").

MAP, ARGUMENT or MAPMM * optional; only 1 allowed; The content of the value is on its own a key value list which will be interpreted, and will populate the _Map persistent variable. If the key is MAPMM or ARGUMENT, the value is a list in mm, while the MAP key is a list in drawing units. The value is a semi column separated list of key values. In this list, the keys can start with an integer specifying the map type. A 70 is always an int. A 40 is a length value. 11 is an indicator for a point.

70PROPINT0 * optional; only 1 allowed; the value must be a number which will be assigned to the PropInt with index 0.

70PROPINT1...70PROPINT99 * see 70PROPINT0, with the only difference that the value will be assigned to the property with the index equal to the number specified after 70PROPINT.

40PROPDOUBLE0 * optional; only 1 allowed; the value must be a double which will be assigned to the PropDouble with index 0.

40PROPDOUBLE1...40PROPDOUBLE99 * see 40PROPDOUBLE0, with the only difference that the value will be assigned to the property with the index equal to the number specified after 40PROPDOUBLE.

PROPSTRING0 * optional; only 1 allowed; the value must be a string which will be assigned to the PropString with index 0.

PROPSTRING1...PROPSTRING99 * see PROPSTRING0, with the only difference that the value will be assigned to the property with the index equal to the number specified after PROPSTRING. 

--------------------------------------------------------------------------------

[Lisp code sample to insert a TSL called _ElemNail:

(Hsb_ScriptInsertNoPrompt (list

    (cons "SCRIPTNAME" "_ELEMNAIL") ; script starts with underscore for HSB buildin tsls

(cons "20ELEMID" ent1)

(cons "20BEAMID" bm1)

(cons "20BEAMID" bm2)

(cons "11PT" (trans pt1 1 0)) ; transform from ucs to wcs

(cons "11PT" (trans pt2 1 0))

(cons "13UCSX" (getvar "UCSXDIR")) ; make sure to add the ucs in the list of args

(cons "13UCSY" (getvar "UCSYDIR"))

(cons "40PROPDOUBLE1" 4.5) ; PropDouble with index 1

(cons "70PROPINT0" zoneindex) ; PropInt with index 0

(cons "70PROPINT3" toolindex) ; PropInt with index 3

(cons "PROPSTRING1" "Just a string") ; PropString with index 1

))

—end sample]


[Lisp code sample to insert a TSL called insertWithMap and accompanying TSL

(Hsb_ScriptInsertNoPrompt (list

    (cons "SCRIPTNAME" "insertWithMap")

(cons "13UCSX" (getvar "UCSXDIR")) ; make sure to add the ucs in the list of args

(cons "13UCSY" (getvar "UCSYDIR"))

(cons "MAP" "70Count;3;40Len;1;11PTX;10;11PTY;20;11PTZ;30") ; Map that is interpreted in drawing units

(cons "MAPMM" "70Count2;3;40Len2;25.4;11PT2X;10;11PT2Y;20;11PT2Z;30;") ; Map that is interpreted with values in mm

))

int nCount = 0;

if (_Map.hasInt("COUNT")) nCount = _Map.getInt("COUNT");

PropInt pCount(5,nCount,"Counter");

double dLen = 0;

if (_Map.hasDouble("LEN")) dLen = _Map.getDouble("LEN");

PropDouble pLen(5,dLen,"Len");

double dLen2 = 0;

if (_Map.hasDouble("LEN2")) dLen2 = _Map.getDouble("LEN2");

PropDouble pLen2(6,dLen2,"Len2");

if (_Map.hasPoint3d("PT")) _Pt0 = _Map.getPoint3d("PT");

_Map = Map(); // reset contents of map

—end sample]

[Lisp code illustrating the _kExecuteKey, for a more extensive example look for setPropValuesFromCatalog 

if (_bOnInsert) {

reportMessage("\n_kExecuteKey is " + _kExecuteKey);

_Pt0 = getPoint();

return;

}



—end sample]

Feedback and Knowledge Base