Introductie CAD LISP

Gebruikers van BricsCAD, en AutoCAD, kunnen processen automatiseren met LISP. Dat een bedrijf daar veel mee kan winnen spreekt voor zich. Maar onbekend maakt onbemind en daarom hebben we zes Nederlandstalige casts gemaakt als een introductie. De voorbeelden zijn praktisch en gaan van makkelijk naar redelijk geavanceerd. De gebruikte code staat hierna en is dus te kopiëren. Via NedCAD kan je een LISP-opleiding volgen maar we kunnen ook programmeren of ondersteunen bij jouw programmeerinspanningen.

Deel 1: Uitleg basisbewerkingen

Uitleg van rekenkundige basisbewerkingen als antwoord op hoeken, afstanden, schaalfactoren, enzovoorts.

Deel 2: Uitleg geavanceerde bewerkingen

Uitleg van bewerkingen als wortels, kwadraten, als antwoord op vragen van CAD-commando’s.

Deel 3: Functie voor eigenschappen

We maken een eenvoudige functie mkbb om eigenschappen byblock te maken en een functie mkbl voor bylayer.

Gebruikte code voor commando MKBB:

1
2
3
4
5
6
7
8
(defun c:mkbb ( / )
	(if
		(ssget)
		(command "chprop" "p" "" "C" "byblock" "LA" "0" "LT" "byblock" "LW" "byblock" "TR" "byblock" "")
		(princ "\nNothing selected!")
	)
	(princ)
)

Gebruikte code voor commando MKBL:

1
2
3
4
5
6
7
8
(defun c:mkbl ( / )
	(if
		(ssget)
		(command "chprop" "p" "" "C" "bylayer" "LT" "bylayer" "LW" "bylayer" "TR" "bylayer" "")
		(princ "\nNothing selected!")
	)
	(princ)
)

Deel 4: LISP-bestanden automatisch laden

Als je een LISP-bestand hebt, hoe laadt je dat, zodat je het kunt gebruiken?

Gebruikte code voor on_doc_load.lsp bevat alle code van de rest van de casts:

1
2
3
4
5
6
(princ "\nStart of on_doc_load")
(load "mkbb")
(load "mkbl")
(defun c:attinc (/ attinc) (load "attinc") (attinc) (princ))
(princ "\nEnd of on_doc_load")
(princ)

Deel 5: Uitleg complexere LISP-routine

Uitleg over hoe een wat complexere LISP-routine werkt.

Gebruikte code voor commando ATTINC:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;; (c)2018 NedCAD
(defun attinc ( / number ent-name att-name att-data) ; Function NOT preceded with c:
	(princ "\nThis utility numbers selected blocks with increments of one by changing the first attribute value.") ; What it does, printed on the command line
	(setq number (getint "\nStarting number: ")) ; Ask for an integer, set variable number.
	(princ "\nSelect first block to number: ") ; After that, ask for a block.
	(while (setq ent-name (car (entsel ""))) ; Select something, while, as long as something is selected.
		(if ; Condition...
			(= (cdr (assoc 0 (entget ent-name))) "INSERT") ; Is it a block?
			(if ; If yes, next round.
				(and ; Both conditions should be met
					(setq att-name (entnext ent-name)) ; Is there a next entity?
					(= (cdr (assoc 0 (entget att-name))) "ATTRIB") ; Is that next entity an attribute?
				)
				(progn ; Good! Then do the next...
					(setq att-data (entget att-name)) ; Retrieve all specs of that attribute...
					(setq att-data
						(subst (cons 1 (itoa number)) (assoc 1 att-data) att-data) ; and replace attribute value with value of variable number.
					) ; A list with new attribute data,
					(entmod att-data) ; modify the entity and
					(entupd att-name) ; update it.
					(setq number (1+ number)) ; Ready and creating next new attribute value, number plus one.
				)
				(princ "\nThis block does not contain an attribute! ") ; Not good. If conditions are not met, print on the command line what went wrong...
			)
			(princ "\nThis entity is not a block! ") ; ditto
		)
		(princ "\nSelect a block or <empty click="" or="" enter="" to="" finish="">: ") ; What to select or what to do to get out of the while loop.
	)
	(princ) ; Finally suppressing LISP messages.
)
;; For on_doc_load.lsp:
; (defun c:attinc (/ attinc) (load "attinc") (attinc) (princ))
</empty>

Deel 6: Testen

Het testen, met uitleg, van de laatste functie die we gemaakt hebben.

Introductie CAD LISP
Scroll to top