Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autolisp to filter Blocks by rotation

Status
Not open for further replies.

Macraym

Nuclear
Mar 27, 2001
1
I am attempting to write an Autolisp routine that in part will make a selection set of specific blocks that have a rotation of zero and another with a rotation of 90.

Ssget will not work with associative code 50 when working with inserts. I am using R14, I am not sure if this makes a difference.

However, I can easily do it with the filter command.

After saving as a named filter, I opened the filter.nfl file in the hope that it would give me a clue.
Unfortunately even copying the dotted pairs as they appear in the file would not make it work.

Any suggestions ?
 
Replies continue below

Recommended for you

Hi,
Before the code, some comments:

Command: (entget (car (entsel)))
Command: Select Object
Pick a block that is inserted with angle 90 - and here is the dump:

((-1 . <Objektname: 14749f0>) (0 . &quot;INSERT&quot;) (330 . <Objektname:
14748f8>) (5 . &quot;3E&quot;) (100 . &quot;AcDbEntity&quot;) (67 . 0) (410 . &quot;Model&quot;) (8 . &quot;0&quot;)
(100 . &quot;AcDbBlockReference&quot;) (2 . &quot;tempi&quot;) (10 220.534 70.6133 0.0) (41 . 1.0)
(42 . 1.0) (43 . 1.0) (50 . 1.5708) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0)
(210 0.0 0.0 1.0))

Indeed group code 50 corresponds to the angle of rotation - but in radians! Not in degrees.
It is half of pi. 3.1416/2 = 1.5708
The precision depends on the setting for units in the drawing.
So, here is the trick:

(cond
((= (dxf 50 ED) (angtof &quot;90.0000&quot;) ) (found90))
((= (dxf 50 ED) (angtof &quot;0.0000&quot;) ) (found00))
((= 1 1)(foundinclined))
);END cond

ED is the entity data from entget. dxf is a one line function below. found90 and found00 are very short functions below.

We are comparing the value of group code 50 with (angtof &quot;90.0000&quot;)
This converts the angle given as text into radians and with default precision - we dont even need to know what the precision is.
So, whatever precision the units in the drawing are set to, applies to both sides of the equation.
An inspiration of mine, lighted up just today. What do you think?

I wrote this code today, for you. I debugged it on Acad2000.
The structure is lightly spread so that other code may easily be inserted
to do things with those blocks. Namely, functions starting with found.. are to be extended.
Hope this is helpful.
The functions used are the same for Acad14 but still, I would appreciate feedback on debugging there.

Have fun.

tigrek@hotpop.com
----------------------------
;file blockrotation.lsp
;sorts all blocks in the drawing according to inclination - vertical, horizontal, inclined.
;ssget can be revised to allow selecting blocks in part of the drawing.
;to remove the &quot;X&quot; from the ssget statement should allow this - but I did not test.

(defun C:BlockRotation()
(setq SSrot00 (ssadd))
(setq SSrot90 (ssadd))
(setq SSrotxx (ssadd))

(setq filt1 (list (cons 0 &quot;Insert&quot;) ))
(setq SUZY (ssget &quot;X&quot; filt1)) ;while

(if (> (sslength SUZY) 0)(progn
;for each filtered block
(setq LENSUZY (sslength SUZY))
(setq COUNTER 0)

(while (setq EDNA (ssname SUZY COUNTER))
(setq ED (entget EDNA))

(cond
((= (dxf 50 ED) (angtof &quot;90.0000&quot;) ) (found90))
((= (dxf 50 ED) (angtof &quot;0.0000&quot;) ) (found00))
((= 1 1)(foundinclined))
);END cond
(setq COUNTER (+ 1 COUNTER))
);END while
));END if progn

(print &quot;total vertical blocks in SSrot00... &quot;)(princ (sslength SSrot90))
(print &quot;total horizontal blocks in SSrot90... &quot;)(princ (sslength SSrot00))
(print &quot;total inclined blocks in SSrotxx... &quot;)(princ (sslength SSrotxx))
(print &quot;Sum total blocks in drawing... &quot;)
(princ (+ (sslength SSrot90)
(sslength SSrot00)
(sslength SSrotxx)
)
)
(princ)
);END defun
;--------
(DEFUN found90()
(ssadd EDNA SSrot90)
(print &quot;Found vertical block. Angle = &quot;)
(princ (dxf 50 ED))
)
;--------
(DEFUN found00()
(ssadd EDNA SSrot00)
(print &quot;Found horizontal block. Angle = &quot;)
(princ (dxf 50 ED))
)
;--------
(DEFUN foundinclined()
(ssadd EDNA SSrotxx)
(print &quot;Found inclined block. Angle = &quot;)
(princ (dxf 50 ED))
)

;----------
(defun dxf (n ed) (cdr (assoc n ed)))
;-----------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor