Problem with boolean functions
The sequel to "Problems with while".
After a closer look for similarities between the programs that don't work properly anymore, I found that they all use boolean functions for creating selection sets.
(Is this the case in your programm John ?)
Here's a code sample, maybe I'm doing something wrong :
[code];extrahiert die Angaben aus den Attributen der Blöcke "Stabpos-li" und "Stabpos-re"
;im Modellbereich und schreibt sie für's Ferro entsprechend formatiert in eine Textdatei
(defun c:Boolean_sample ( / anzahl attpos attanz attdm atttyp atthaka attLA attLB attLC attLD attLE atthake atttxt auswahl eliste elname eltxt name posblock zaehler)
;auslesen des aktuellen Zeichnungsnamens und generieren eines Vorgabenamens für die EL als fex-Datei (Import Ferro)
(setq name (getvar "dwgname"))
(setq name (strcat "D:\\Elisten\\" (substr name 1 8) ".fex"));ergänzen um Dateityp, 8-3 Dateiformat da Ferro DOS-Programm
(setq eliste (open name "a"))
(setq auswahl (ssget "_X" (list (cons -4 "
(cons -4 " (cons 0 "INSERT")
(cons 2 "Stabpos-re")
(cons 67 0)
(cons -4 "and>")
(cons -4 " (cons 0 "INSERT")
(cons 2 "Stabpos-li")
(cons 67 0)
(cons -4 "and>")
(cons -4 "or>")
)))
(setq anzahl (sslength auswahl))
(setq zaehler 0)
(while (< zaehler anzahl)
; Element-Name der Objekte ermitteln und Attributwerte auslesen
(setq elname (ssname auswahl zaehler))
(setq elname (entnext elname))
(setq attpos (entget elname))
(setq attpos (cdr (assoc 1 attpos)))
(setq elname (entnext elname))
(setq attanz (entget elname))
(setq attanz (cdr (assoc 1 attanz)))
(setq elname (entnext elname))
(setq attdm (entget elname))
(setq attdm (cdr (assoc 1 attdm)))
(setq elname (entnext elname))
(setq atttyp (entget elname))
(setq atttyp (cdr (assoc 1 atttyp)))
(setq elname (entnext elname))
(setq atthaka (entget elname))
(setq atthaka (cdr (assoc 1 atthaka)))
(setq elname (entnext elname))
(setq attLA (entget elname))
(setq attLA (cdr (assoc 1 attLA)))
(setq elname (entnext elname))
(setq attLB (entget elname))
(setq attLB (cdr (assoc 1 attLB)))
(setq elname (entnext elname))
(setq attLC (entget elname))
(setq attLC (cdr (assoc 1 attLC)))
(setq elname (entnext elname))
(setq attLD (entget elname))
(setq attLD (cdr (assoc 1 attLD)))
(setq elname (entnext elname))
(setq attLE (entget elname))
(setq attLE (cdr (assoc 1 attLE)))
(setq elname (entnext elname))
(setq atthake (entget elname))
(setq atthake (cdr (assoc 1 atthake)))
(setq elname (entnext elname))
(setq atttxt (entget elname))
(setq atttxt (cdr (assoc 1 atttxt)))
(setq eltxt (strcat attpos "#" attanz "#" attdm "#0#" atttyp "#" atthaka "#" attLA "#" attLB "#" attLC "#" attLD "#" attLE "#" atthake "#" atttxt))
(write-line eltxt eliste)
(setq zaehler (1+ zaehler))
);while
(close eliste)
);defun[/code]
If you want to try it just make sure that the directory on line 11 exists. I also attach a sample drawing to extract those attribute values.
The writeout in the file should look like this :
1#81#16#0#3#o#65#28#150#0#0#o#
2#76#16#0#3#o#70#38#674#0#0#o#
3#2#16#0#3#o#70#38#597#0#0#o#
7#6#16#0#2#l#80#120#0#0#0#o#
14#2#14#0#8#o#25#88#25#0#0#o#
Instead it starts from the bottom up. As the list will be use for a bill of materials, it's important that it starts with Nr.1. It's not a problem with five items on the bill,
but if there are 150 items ...
I suspect that between V13.2.4 and V13.2.10 something happened to the boolean functions, it's still there in V14. Did someone make similar observations ?
After a closer look for similarities between the programs that don't work properly anymore, I found that they all use boolean functions for creating selection sets.
(Is this the case in your programm John ?)
Here's a code sample, maybe I'm doing something wrong :
[code];extrahiert die Angaben aus den Attributen der Blöcke "Stabpos-li" und "Stabpos-re"
;im Modellbereich und schreibt sie für's Ferro entsprechend formatiert in eine Textdatei
(defun c:Boolean_sample ( / anzahl attpos attanz attdm atttyp atthaka attLA attLB attLC attLD attLE atthake atttxt auswahl eliste elname eltxt name posblock zaehler)
;auslesen des aktuellen Zeichnungsnamens und generieren eines Vorgabenamens für die EL als fex-Datei (Import Ferro)
(setq name (getvar "dwgname"))
(setq name (strcat "D:\\Elisten\\" (substr name 1 8) ".fex"));ergänzen um Dateityp, 8-3 Dateiformat da Ferro DOS-Programm
(setq eliste (open name "a"))
(setq auswahl (ssget "_X" (list (cons -4 "
(cons -4 " (cons 0 "INSERT")
(cons 2 "Stabpos-re")
(cons 67 0)
(cons -4 "and>")
(cons -4 " (cons 0 "INSERT")
(cons 2 "Stabpos-li")
(cons 67 0)
(cons -4 "and>")
(cons -4 "or>")
)))
(setq anzahl (sslength auswahl))
(setq zaehler 0)
(while (< zaehler anzahl)
; Element-Name der Objekte ermitteln und Attributwerte auslesen
(setq elname (ssname auswahl zaehler))
(setq elname (entnext elname))
(setq attpos (entget elname))
(setq attpos (cdr (assoc 1 attpos)))
(setq elname (entnext elname))
(setq attanz (entget elname))
(setq attanz (cdr (assoc 1 attanz)))
(setq elname (entnext elname))
(setq attdm (entget elname))
(setq attdm (cdr (assoc 1 attdm)))
(setq elname (entnext elname))
(setq atttyp (entget elname))
(setq atttyp (cdr (assoc 1 atttyp)))
(setq elname (entnext elname))
(setq atthaka (entget elname))
(setq atthaka (cdr (assoc 1 atthaka)))
(setq elname (entnext elname))
(setq attLA (entget elname))
(setq attLA (cdr (assoc 1 attLA)))
(setq elname (entnext elname))
(setq attLB (entget elname))
(setq attLB (cdr (assoc 1 attLB)))
(setq elname (entnext elname))
(setq attLC (entget elname))
(setq attLC (cdr (assoc 1 attLC)))
(setq elname (entnext elname))
(setq attLD (entget elname))
(setq attLD (cdr (assoc 1 attLD)))
(setq elname (entnext elname))
(setq attLE (entget elname))
(setq attLE (cdr (assoc 1 attLE)))
(setq elname (entnext elname))
(setq atthake (entget elname))
(setq atthake (cdr (assoc 1 atthake)))
(setq elname (entnext elname))
(setq atttxt (entget elname))
(setq atttxt (cdr (assoc 1 atttxt)))
(setq eltxt (strcat attpos "#" attanz "#" attdm "#0#" atttyp "#" atthaka "#" attLA "#" attLB "#" attLC "#" attLD "#" attLE "#" atthake "#" atttxt))
(write-line eltxt eliste)
(setq zaehler (1+ zaehler))
);while
(close eliste)
);defun[/code]
If you want to try it just make sure that the directory on line 11 exists. I also attach a sample drawing to extract those attribute values.
The writeout in the file should look like this :
1#81#16#0#3#o#65#28#150#0#0#o#
2#76#16#0#3#o#70#38#674#0#0#o#
3#2#16#0#3#o#70#38#597#0#0#o#
7#6#16#0#2#l#80#120#0#0#0#o#
14#2#14#0#8#o#25#88#25#0#0#o#
Instead it starts from the bottom up. As the list will be use for a bill of materials, it's important that it starts with Nr.1. It's not a problem with five items on the bill,
but if there are 150 items ...
I suspect that between V13.2.4 and V13.2.10 something happened to the boolean functions, it's still there in V14. Did someone make similar observations ?
0
Comments
-
I'm sorry, for some reason the code has bits missing around the boolean function. For completeness I attach the whole file.0
-
Quote from the V13 Release Notes:
Version 13.2.5:
SR37959 - LISP: entity order in selectionset (retrieved by (ssname) + (ssnamex) functions) is now AutoCAD compatible for selection modes "X", "A", "C" and "W".
To reverse the order you can use something like this:
[code](reverse (vle-selectionset->list selSet))[/code]0 -
Sorry boolean is beyond my vocabulary, but this is my routine which is generally reliable while sometimes falling into a pattern of only working every second try.
When it fails it writes the first line on screen before giving up.
[code](DEFUN c:CAT ()
(SETVAR "CMDECHO" 0)
(if (/= 0 (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))))
(progn
(princ "\nTextsize must be 0 ")(terpri))
(progn
(setq oldl (getvar "clayer"))
(COMMAND "LAYER" "M" "DEFPOINTS" "")
(SETQ OLDP (GETVAR "LUPREC"))
(SETVAR "LUPREC" 0)
(setq ss (ssget "x" (list (cons 0 "ATTRIB"))) n 0 p1 nil p1 (getpoint "\nStart Point: "))
(while (/= n (sslength ss))
(setq a (ssname ss n) b (entnext a) c (entnext (entnext a))
d (entnext (entnext (entnext a)))
p (cdr (assoc 2 (entget b)))
q (cdr (assoc 1 (entget b)))
p2 (polar p1 0 (* (getvar "textsize") 12))
p3 (polar p1 0 (* (getvar "textsize") 24))
p4 (polar p1 0 (* (getvar "textsize") 36)))
(command "text" p1 "" "" p)
(command "text" p2 "" "" q)
(if (= "ATTRIB" (cdr (assoc 0 (entget c))))
(progn
(setq r (cdr (assoc 1 (entget c))))
(command "text" p3 "" "" r)))
(if (= "ATTRIB" (cdr (assoc 0 (entget d))))
(progn
(setq s (cdr (assoc 1 (entget d))))
(command "text" p4 "" "" s)))
(setq n (1+ n) p1 (polar p1 (* 1.5 pi)(* (getvar "LTSCALE") 0.4)))
)
(SETVAR "LUPREC" OLDP)
(command "layer" "S" oldl "")
)))[/code]0 -
Roy - thanks for the hint. The change is official then, reading the release notes would obviously have helped.
I solved the problem by processing the entities not incrementaly but decrementaly, all seems to be well again.
John - Boolean functions (and, or, xor, not), an entity is selected only when certain combined conditions are true, in my case the blocks "Stabpos-re" and "Stabpos-li".
Re your code, I gave it a go on my machine, it stopped at (SSLENGTH SS) missing a selection, something isn't there, something present in your drawings but not in mine ? I'm affraid that's how far I came.
And re vocabulary - "terpri" ? "Luprec" ? I've got my blind spots too.0 -
Oh, those are just terminate print and linear units precision, but while I know And Or etc I don't even know who Bool was.
Sounds like mine was no help for you, if you saw something in common it might have helped me too.
It only goes for blocks with a max of about 3 attributes (that's all I need), and probably fall over if there is none or maybe only one block.
It does generally work on files from other people.
0
This discussion has been closed.