Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find object associated to a Field

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
tcorey
3728 Views, 8 Replies

Find object associated to a Field

We use multi-leader objects in our drawings. When the multi-leader and its value are to be replicated throughout the drawing, we create mleaders with fields that show the contents of the first mleader. That way we can update only the value in the first mleader and all of its children will update as well. It works nicely for us.

 

Here comes one snag. If one of us opens a drawing with which we are not intimately familiar, we don't know which mleader is the parent of which children. There might be fifty parents and four hundred children in a drawing so going through them by hand is a big productivity drain.

 

What I need to do is write a routine that will let the user select the mleader that includes the field and have the routine highlight and/or zoom to the parent object.

 

I thought I should be able to find that info in the dxf codes for the mleader, but I am either missing it or it's not there.

 

Thanks for any help or advice you might supply,

 

Tim

 



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
8 REPLIES 8
Message 2 of 9
tcorey
in reply to: tcorey

I have discovered the topic "Extension Dictionary and Persistent Reactors" which just has to be how I will access this information.

 

Someone stop me if I am going down the wrong road. Or better yet, point me in the right direction.

 

If an mleader includes a field, it has a dxf 102 code indicating reference to a dictionary. It then shows a code 360 with an entity name. Is this the entity that the field is dependent upon? In my research it doesn't seem to be, but this value must somehow be telling me who the field's parent is. I just can't crack the nut.

 

Thanks if you can help.

 


Tim

 

 

 



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 3 of 9
jdvillarreal
in reply to: tcorey

Try entget on code 360 until code 331, which identifies the object used for the field,becomes available.

I've attached code to check against your own.

 

 

 

Message 4 of 9
tcorey
in reply to: jdvillarreal

Thank you, JD!



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
Message 5 of 9
jetxcc
in reply to: tcorey

found this post...it's a life saver!! I'll admit...I'm not very good with the LISP thing, never really had a use for it, but I definitely see the advantages of it, just never had much need for it in what i do, until recently. ashamedly it took me awhile to figure out you had to type "GO" and click an object before it would work...felt like an igit! 8-?

now for the questions...is there a way to adjust the zoom so that it doesn't fill up the screen but maybe 3/4 of the way so that you can see the entities around the reference object? and is there a way to cycle through the references if your field formula references more than one object?

 

 

thanks for the great LISP code. 

Message 6 of 9
RocksterB
in reply to: tcorey

The availability of this routine was right on time! Autodesk should park this command on one of AutoCAD's ribbon panels. Thanks and kudos!

Message 7 of 9
vladimir_michl
in reply to: RocksterB

There is an old FieldLink utility which draws temporary lines/arrows between linked (dependent) objects/fields. See:

http://www.cadforum.cz/cadforum_en/fieldlink-to-display-links-between-fields-and-objects-tip6795

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

Message 8 of 9
jetxcc
in reply to: tcorey

(defun c:ShowFieldLink ( / en ed fld obj IsLink)

(vl-load-com)

(setq en (car (entsel "Select a field: ")))

(setq ed (entget en))

(if (OR (= (cdr (assoc 0 ed)) "MTEXT")"TEXT")

  (if (cdr (assoc 360 ed))

      (if (setq IsLink 

            (assoc 331 

              (entget (cdr (assoc 360 

                (entget (cdr (assoc 360 

                  (entget (cdr (assoc 360 

                    (entget (cdr (assoc 360 ed)))))))))))))

                    )

        (progn

          (setq fld (entget (cdr IsLink)))

          (setq obj (cdr (assoc -1 fld)))

          (grdraw (cdr (assoc 10 ed)) (cdr (assoc 10 fld)) 1 1)

          (vla-Highlight (vlax-ename->vla-object obj) :vlax-True)

          )

        (progn

          (vlr-beep-reaction)

          (princ "\nThat field is not associated with an object.")

          )

        )

     )

  (progn

      (vlr-beep-reaction)

      (princ "\nThat is not even a field.")

      )

  )

(princ)

)



(defun c:SFL () (c:ShowFieldLink))



(princ "ShowFieldLink loaded. Type  SFL  to run.")

(princ)

^^^THIS one draws a temporary line to the referenced object that disappears when you scroll, zoom, etc. 

 

(defun c:DrawFieldLink (); ( / en ed on od ln ld ss)

(vl-load-com)

(setq en

(car (entsel "\nSelect a field, or MTEXT containing a field: ")))

(setq ed (entget en))

(if (OR (= (cdr (assoc 0 ed)) "MTEXT")"TEXT")

(if (cdr (assoc 360 ed)) ;;if there is a field here somewhere

(progn

(while (assoc 360 ed) (setq ed (entget (cdr (assoc 360 ed)))))

(if (assoc 331 ed) ;; if the field is linked to an object

(progn

(setq on (cdr (assoc 331 ed)))

(setq od (entget on)) ;;object data

(setq ln (cdr (assoc 8 od)))

(setq ld (tblsearch "LAYER" ln))

(if (or

(= (logand (cdr (assoc 70 ld)) 1) 1) ;;frozen layer

(minusp (cdr (assoc 62 ld))) ;;OFF layer

)

(progn

(vlr-beep-reaction)

(princ (strcat "\nNote: linked object's layer, "

(strcase ln)

", is frozen or off."))

)

(progn ;; zoom draw, highlight

(if (equal (assoc 410 (entget en)) (assoc 410 od))

(progn ;;zoom out if needed, then draw link

(if (or 

(=(getvar "tilemode")1) 

(=(getvar "cvport")1)

)

(progn

(setq ss (setvisible))

(if (not 

(and (ssmemb en ss) (ssmemb on ss))

)

(progn

(command "._zoom"

(cdr (assoc 10 (entget en))) 

(cdr (assoc 10 od))

)

(command "._zoom" ".8x")

)

)

)

)

(command "line" (cdr (assoc 10 (entget en))) (cdr (assoc 10 od)) "")

);progn

(progn

(vlr-beep-reaction)

(princ 

"\nNote: field & object are not in same space.")

)

) ;;if same space

(vla-Highlight 

(vlax-ename->vla-object on) :vlax-True)

)

);;if frozen

)

(progn

(vlr-beep-reaction)

(princ "\nThat field is not linked to an object.")

)

);; if linked

)

(progn

(vlr-beep-reaction)

(princ "\nThat MTEXT does not contain a field.")

)

)

(progn

(vlr-beep-reaction)

(princ "\nThat is not even MTEXT, much less a field.")

)

)

(princ)

)

(defun c:DFL () (c:DrawFieldLink))

(defun SetVisible ( / x y dx dy result *error*)

(defun *error* ()(command "._ucs" "_p"))

(setvar "cmdecho" 0)

(command "._ucs" "_view")

(setq x (car (getvar "VIEWCTR"))

y (cadr (getvar "VIEWCTR"))

dy (/ (getvar "VIEWSIZE") 2.0)

dx (* dy (/ (car (getvar "SCREENSIZE"))

(cadr (getvar "SCREENSIZE"))

1.0))

result (ssget "C"

(list (- x dx) (- y dy)) ;LL

(list (+ x dx) (+ y dy)) ;UR

)

)

(command "._ucs" "_p")

(setvar "cmdecho" 1)

result

)

(princ "DrawFieldLink loaded. Type DFL to run.")

(princ)

^^^this one draws a line that you have to erase 

Message 9 of 9
RocksterB
in reply to: jetxcc

Those are quite helpful. Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost