Jump to content
manddarran

Determine what associative dimensions are attached to.

Recommended Posts

manddarran

Is there anyway to determine what each end of a dimension is attached to when you are using associative dimensions?

 

What I am trying to determine is the dimension attached to a xref or an inserted block on each end?

Share this post


Link to post
Share on other sites
JohnM

give this a try

 

 
(defun c:asdm (/ ss ssm ent obj1 obj2 lbl1 lbl2 tsr)
(while (not(setq ss (ssget "_:S" '((0 . "Dimension")(102 . "{ACAD_REACTORS"))))))
  (if ss
(progn
(setq ssnm (ssname ss 0))
(setq ent(entget(cdr (assoc 330(entget ssnm)))))
(setq obj1 (entget(cdr(assoc -1(entget(cdr(assoc  331 ent)))))))
  (setq obj2 (entget(cdr(assoc -1(entget(entnext(cdr(assoc  331 ent)))))))) 
  (setq lbl1 (cdr(assoc 0 obj1)))
  (setq lbl2 (cdr(assoc 0 obj2)))
  (if (=(cdr(assoc 0 obj1))"INSERT")
(progn
(setq tsr(tblsearch "block" (cdr(assoc 2 obj1))))
(if (=(cdr(assoc 70 tsr)) 0)(setq lbl1 "Block")(setq lbl1 "XREF"))
);_progn
);_if
(if (=(cdr(assoc 0 obj2))"INSERT")
(progn
(setq tsr(tblsearch "block" (cdr(assoc 2 obj2))))
(if (=(cdr(assoc 70 tsr)) 0)(setq lbl2 "Block")(setq lbl2 "XREF"))
);_progn
);_if
(alert (strcat "First Attachment to "lbl1 "\n" "Second Attachment to "lbl2))
);_progn
);_if
  (princ)
 );_defun

Share this post


Link to post
Share on other sites
manddarran

Thank you for your help. It is listing my xref as a block.

 

Nevermind, I tried a another dwg and it is working fine, there was something wrong with that dwg. Thx.

Share this post


Link to post
Share on other sites
manddarran

Well I spoke to soon, I don't seem to be able to get consistant results. Must be how I am doing the dimensions. One time I get a xref, the next a block. I am doing a dim align and select the insert of the block and then perpendicular to the wall and it is giving me two blocks.

Share this post


Link to post
Share on other sites
manddarran

I have tried all sorts of iterations, but this routine works once in a while and far between. Not sure why as the code looks correct. Some times it just returns the same block on one end of the dimension.

Share this post


Link to post
Share on other sites
manddarran

It appears that the Entnext function is getting the next entity that is in the data base and not the next reactor in the list. Here is the ent variable

 

((-1 . <Entity name: 7ffff7fc620>) (0 . "DIMASSOC") (5 . "59D3A") (102 . 
"{ACAD_REACTORS") (330 . <Entity name: 7ffff7fc580>) (102 . "}") (330 . <Entity 
name: 7ffff7fc580>) (100 . "AcDbDimAssoc") (330 . <Entity name: 7ffff7fc4b0>) 
(90 . 3) (70 . 0) (71 . 0) (1 . "AcDbOsnapPointRef") (72 . 10) (331 . <Entity 
name: 7ffffc3d470>) (73 . 2) (91 . 0) (40 . 0.319045) (10 0.0 0.0 0.0) (75 . 0) 
(1 . "AcDbOsnapPointRef") (72 . 7) (331 . <Entity name: 7ffffc39c20>) (73 . 2) 
(91 . 0) (40 . 0.0) (10 0.0 0.0 0.0) (75 . 0))

 

There are three entities there but is getting one and not the next.

 

How do I parse thru this since there are two 330 codes?

Share this post


Link to post
Share on other sites
JohnM

I just threw it together and did not do a lot of experimenting with it. I’ll play around when I get a chance and see about fixing it.

Share this post


Link to post
Share on other sites
manddarran
I just threw it together and did not do a lot of experimenting with it. I’ll play around when I get a chance and see about fixing it.

 

I appreciate the help. I can see the correct entities listed there, just cant get at them.

Share this post


Link to post
Share on other sites
JohnM

The entity returned is a list. You can use the (foreach) function to parse through the list testing each item in the list to meet you criteria. This is also one way to return polyline vertices since there are multiple DXF code with the same number.

Example:

(Setq lst1 '());_set up a blank list

(foreach item ent

(if (= (car item) 330)(setq lst1 (cons (cdr item) lst1)))

);_foreach

This will make a list of all 330 items then you can access each item in the list and perform what ever you need to.

Share this post


Link to post
Share on other sites
alanjt

How do I parse thru this since there are two 330 codes?

 

(vl-remove-if-not
 (function (lambda (x) (eq 330 (car x))))
 EntLst)

Share this post


Link to post
Share on other sites
manddarran

Thank you for all the help! Got it licked:

 

;Using snip its from JohnM's code.
;will list the two items that are attached to associative dimensions.
;JohnM
(defun c:asdm ();/ sel dataEntity dataDict dataDimAssoc)
(while (not(setq ss (ssget "_:S" '((0 . "Dimension")(102 . "{ACAD_REACTORS"))))))
  (if ss
       (progn
           (setq ssnm (ssname ss 0))
           ;JohnM
           ;MandDarran
           (setq datae (entget ssnm))
           (setq dataD (entget (cdr (assoc 330 dataE))))
           (setq dataDim (entget (cdr (assoc 331 dataD))))
           (setq dataDim2 (entget (entnext(cdr (assoc 331 dataD)))))
           (if (= (car item) 330)(setq lst1 (cons (cdr item) lst1)))
           (Setq lst1 '());_set up a blank list
           (foreach item datad
               (if (= (car item) 331)(setq lst1 (cons (cdr item) lst1)))
               );_foreach
           (setq assoc1 (car lst1))
           (setq assoc2 (cadr lst1)) 
           (setq obj1 (entget assoc1)) 
           (setq obj2 (entget assoc2)) 
           (setq lbl1 (cdr(assoc 0 obj1)))
           (setq lbl2 (cdr(assoc 0 obj2)))
           ;MandDarran
           ;JohnM
           (if (=(cdr(assoc 0 obj1))"INSERT")
                (progn
                (setq tsr(tblsearch "block" (cdr(assoc 2 obj1))))
                (if (=(cdr(assoc 70 tsr)) 0)(setq lbl1 "Block")(setq lbl1 "XREF"))
                );_progn
            );_if
            (if (=(cdr(assoc 0 obj2))"INSERT")
                (progn
                (setq tsr(tblsearch "block" (cdr(assoc 2 obj2))))
                (if (=(cdr(assoc 70 tsr)) 0)(setq lbl2 "Block")(setq lbl2 "XREF"))
                );_progn
            );_if
            (alert (strcat "First Attachment to "lbl1 "\n" "Second Attachment to "lbl2))
            (princ)
        );_progn
);_if
(princ)
)

Share this post


Link to post
Share on other sites
Lee Mac

A couple of MAssoc functions I had in the archive:

 

(defun massoc1 ( x lst )
 (vl-remove-if-not
   (function
     (lambda (pair) (= x (car pair)))) lst))


(defun massoc2 ( x lst )
 (if lst
   (if (= x (caar lst))
     (cons (car lst) (massoc2 x (cdr lst)))
     (massoc2 x (cdr lst)))))

 

or there's acet-list-m-assoc :)

Share this post


Link to post
Share on other sites
manddarran

I am sure what I wrote could be simplified, but man this stuff gets hard to follow. Thx Lee

Share this post


Link to post
Share on other sites
Lee Mac

I'm not sure if this is an easier way to approach it? (I don't really like dealing with Dictionaries in ActiveX :geek: )

 

 

(defun c:asdm ( / massoc ss obj Dic )
 ;; Lee Mac  ~  13.04.10
 
 (defun massoc ( x lst )
   (if lst
     (if (= x (caar lst))
       (cons (car lst) (massoc x (cdr lst)))
       (massoc x (cdr lst)))))
 
 (if (and (setq ss (ssget "_+.:E:S" '((0 . "DIMENSION") (102 . "{ACAD_REACTORS"))))
          (eq :vlax-true (vla-get-HasExtensionDictionary
                           (setq obj (vlax-ename->vla-object (ssname ss 0))))))
   (progn
     (setq Dic (vla-getExtensionDictionary obj))
     (princ (apply (function strcat)
                   (mapcar (function strcat) '("\nObject 1: " "\tObject 2: ")
                     (mapcar (function (lambda (x) (cdr (assoc 0 (entget (cdr x))))))
                       (massoc 331 (entget (vlax-vla-object->ename
                                             (vla-GetObject Dic "ACAD_DIMASSOC"))))))))))
 (princ))

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×