"custom definied entities" with CADCAL - without programming!
This is a sample to show how easy a standard CAD script, which has been used to create drawing parts, can bei parametrisised, so that we get something similar to "user defined entities" or "dynamic blocks". Please use the most recent (from July 2nd 2024 or
newer) beta-version of CADCAL, downloadable from www.archtools.de/cadcal.zip.
Let's use a simple script like that (simply copy&paste into an empty text file and save that as <myscript>.scr):
;;***** start of script
(if (not long) (setq long 80))
(if (not wide) (setq wide 120))
(if (not ORIGIN) (setq ORIGIN '(0 0 0)))
;;
(setq p1 ORIGIN)
(setq p2 (list (+ (car p1) long) (cadr p1)))
(setq p3 (list (car p2) (+ (cadr p1) wide)))
(setq p4 (list (car p1) (cadr p3)))
._line
!p1
!p2
!p3
!p4
_cl
._line !p1 !p3
._line !p2 !p4
;;***** end of script
Of course you would prefer to use the easier CADCAL/GeomCAL syntax (i.e. "CAL P1=ORIGIN") instead of Lisp, but this sample is to demonstrate that any script can be used.
You can execute that script with the standard SCRIPT command of your CAD system, and it will create a drawing part according to it's definition. When you define LONG and WIDE before you start the script, then it will use this values instead of the default values from the script.
Now CADCAL enables a different approach to define the variables with default values, using the CADCAL function IMPORT(), which is not available in GeomCAL. IMPORT() allows you to initialize any number of variables with default values, which can be referred to later in the script.
;***** start of script
CAL import(LONG,80,WIDE,120)
;;
(setq p1 ORIGIN)
(setq p2 (list (+ (car p1) LONG) (cadr p1)))
(setq p3 (list (car p2) (+ (cadr p1) WIDE)))
(setq p4 (list (car p1) (cadr p3)))
._line
!p1
!p2
!p3
!p4
_cl
._line !p1 !p3
._line !p2 !p4
;;***** end of script
At first view there is no big difference between both scripts. IMPORT(LONG,80,WIDE,120) does the very same as the Lisp lines in the first script: the variables get default values. When CADCAL is loaded (necessary to process the script line "CAL import(LONG,80,WIDE,120)"), then you still can execute this script with the standard SCRIPT command of your CAD system.
BTW: the variable name ORIGIN is predefined in CADCAL scripts ("CALScripts") as the insertion point at which the drawing is placed. So we don't need to define this variable in the CALScript.
And now comes the magic part. When you use the CALSCRIPT command instead of the SCRIPT command then you will be asked for an insertion point (which is refered to as ORIGIN in the script) and a rotation angle, very much the same as with a block insertion. And you will be asked for new values of the variables which are defined by the IMPORT() function in your script. And then the drawing will be created as expected, and it consists of an anonymous block. It is a CALSCRIPT object.
And this CALSCRIPT object can be modified: use the CADCAL command CC-MODIFY, click at the object, and give new values for it's variables. And the CALSCRIPT object will change it's appearence immediately.
You can move, rotate, and copy these CALSCRIPT objects, change their layer, color, linetye and so on, attach XDATA and XDictionaries, and whatever you want to, and each individual object will still remain editable and still keep all it's modifications. You can give away a DWG file containing these objects, and the receiver only needs the freely available CADCAL to be able to edit these objects.
And the modification of the parameters of a CALSCRIPT object can also be done by Lisp. Simply select a CALSCRIPT object and use the CC-PROPERTY-GET and CC-PROPERTY-SET functions:
(setq en (car (entsel))
And now use
(cc-property-get en 'WIDE)
to read the value of the property WIDE
And of course with
(cc-property-set 'WIDE 120)
you can change the value of WIDE of this object
You get all object properties with this function call
(cc-property-get en nil)
And you can set multiple properties with one single function call
(cc-property-set en '((WIDE 120) (LONG 80)) nil)
And this even enables you to create animations in your CAD system:
(setq wi 150 le 50)
(repeat 100 (cc-property-set en (list (list 'WIDE wi) (list 'LONG le)) nil) (setq wi (- wi 1) le (+ le 1)))
Have fun playing with CADCAL and CALSCRIPT objects!