If value in attribute is true

If value in attribute is true

andreas7ZYXQ
Advocate Advocate
678 Views
1 Reply
Message 1 of 2

If value in attribute is true

andreas7ZYXQ
Advocate
Advocate

Hi

 

Im kind of stuck here.

 

I want to look if a attribute SKALA exists in the drawing

and check if it contains the value 1:1.

If this statements is true, i wamt so sett my string mo to "funk"
To make it more secure i would like to see if its inside a block and if the block exists in the drawing.

Could someone give me a hand withe the final steps and maybe also explain why its not working here.

 

(setq ss (entnext))
(while ss
 (setq ed (entget ss))
 (if (= "ATTRIB" (cdr (assoc 0 ed)))
  (if (= "SKALA" (cdr (assoc 2 ed)))
	(if (= "1:1" (assoc 1 ed))
	(setq mo "funk")
	)
  )
 )
 (setq ss (entnext ss))
)
(setq ed nil)
(princ)


Thanks for your help. And sorry for my bad english

0 Likes
679 Views
1 Reply
Reply (1)
Message 2 of 2

Moshe-A
Mentor
Mentor

@andreas7ZYXQ hi,

 

your code is good except the first line

(setq ss (entnext))

cause what it 'says' is get the first entity in drawing but you expect it to be a block reference but you can not be sure that this is the case?!

 

here is my fixed code (did not test it)

 

(defun c:test (/ ssg i ss ed mo)
 ; pause for user select block references
 (if (setq ssg (ssget '((0 . "insert") (66 . 1))))
  (progn
   (setq i -1)
   (repeat (sslength ssg)
    (setq ss (ssname ssg (setq i (1+ i))))
    (setq ss (entnext ss) ed (entget ss))
    (while (/= (cdr (assoc 0 ed)) "SEQEND")
     (if (and
	   (eq (cdr (assoc 2 ed)) "SKALA")
           (eq (cdr (assoc 1 ed) "1:1")
	 )
      (setq mo "funk")
     ); if

     (setq ss (entnext ss) ed (entget ss))
    ); while
   ); repeat
  ); progn
 ); if

 (princ)
); c:test

 

when iterating block reference (insert) the entities (objects) inside are ATTRIB and the last object is a SEQEND

 thus you can check if last object is reached to end the loop.

 

moshe

0 Likes