Jump to content

Getting objectID/ename of a polyline from a field used in an attribute inside a block


Recommended Posts

Posted

Hallo again, I'm back with an issue and my limited amount of experience is kicking in. I'd really appreciate if someone could hint me into the correct direction. 


I'm currently trying to get the center of area from a polyline using lisp. As far as to get it from a polyline if I directly select it is not an issue. I'm converting it to a region, write and read the output from massprop into/from a file and have them by hand to use them further down the road. 

But my real usecase is, that I need to loop through a selection set containing several blocks. Each of those has an attributes called "AREA" inside. That is filled with a field referencing the area of a closed polyline. (I use a slightly modified version of Lee Macs "Area field to attribute" macro to do so.) As the area indicated in the attribute is updating when I modify the polyline and regenerate, I'm pretty sure that they are linked. Therefore I'd like to use a piece of code to identify the referenced polyline and get the ObjectID/Ename of it for the use further down the road in my macro. 
I've tried to modify Lee Macs "Field Objects" lisp and get the clues out of there, but failed doing so. :(
Anyone who can help me there? 

 

Thank you and best regards, 

Ament

Posted

It would be a great idea if you attached a dwg with some of those blocks

Posted

Hi GALVCVS, your wish is my command with that one. 

 

Please find a sample attached. The actual file is to big to be shared. Just imagine it to contain over 1k of those blocks. Therefore an automation instead of doing it manually. 

 

BR, Ament

DWG-Sample_ObjID_from_Attributefield.dwg

Posted

Hi Lee Mac, thank you for your help, I've tried to use it without any modification, but when selecting the block that is containing the attribute I only get back "Selected object is not a field, or field doesn't reference any objects." I guess when selecting the block I'm missing the link to drill down to the attribute called "AREA" to pass that into the function from above. 
Unfortunately I've big difficulties to find that using my macro skill. :(

Posted

Hi Ament,

Blockedit the block and update the Invisible property of the Attribute definition (Area) object to "No". close the block editor and save. Type ATTSYNC at the command line and select the block to be updated. The filed value to be selected should now be visible.

image.thumb.png.dfd461f0fab3f76d8f9adbea87fa8cf7.png

Posted
8 hours ago, Ament said:

Hi Lee Mac, thank you for your help, I've tried to use it without any modification, but when selecting the block that is containing the attribute I only get back "Selected object is not a field, or field doesn't reference any objects." I guess when selecting the block I'm missing the link to drill down to the attribute called "AREA" to pass that into the function from above. 
Unfortunately I've big difficulties to find that using my macro skill. :(

 

You'll need to invoke the function with the attribute entity, or select the attribute reference using the test program (which uses an nentsel selection).

Posted

I think a test implementation of Lee's code for your blocks could be:

 

Quote
(LM:fieldobjects
  (vlax-vla-object->ename
    (nth
      3
      (safearray-value
	(variant-value
	  (vla-getattributes
	    (vlax-ename->vla-object
	      (car
		(entsel
		  "\nSelect an \'AREA ATTRIBUTE\' block to get entity name of linked polyline..."
		)
	      )
	    )
	  )
	)
      )
    )
  )
)

 

 

Posted

I wouldn't rely on the attribute order, but rather acquire the attribute reference entity using its tag identifier, e.g.:

(cond
    (   (not (setq ent (car (entsel)))))
    (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
        (princ "Selected object is not a block.")
    )
    (   (/= 1 (cdr (assoc 66 enx)))
        (princ "\nSelected block is not attributed.")
    )
    (   (progn
            (setq att (entnext ent)
                  atx (entget  att)
            )
            (while (and (= "ATTRIB" (cdr (assoc 0 atx))) (/= "AREA" (cdr (assoc 2 atx))))
                (setq att (entnext att)
                      atx (entget  att)
                )
            )
            (= "SEQEND" (cdr (assoc 0 atx)))
        )
        (princ "\nAREA attribute not found in selected block.")
    )
    (   (LM:fieldobjects att)   )
)

 

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...