Jump to content

Define a attribute within a block to reflect the area of a polyline


Recommended Posts

Posted

Hello together,

I've written some amature like lisp macros up to know but I'm stuggeling with my latest idea. Somehow I can't get an idea even how to approach it well. Can someone help?

 

The starting point is a drawing in which I have multiple different blocks. One of them is added frequently is a block containing several attributes like "Category", "Number", "Roomtype" and "Area". My special issue is the "Area"-attribute. As of now I doubleclick the block to enter the enhances attribute editor, select the arrtibute "Area", rightclick into the value to insert a field. In the newly opened field definition I select as "Field names" --> Object, select an closed boundary from the drawing, chose the property "Area" set the precision to "0" and open the "Additional Format ..." window to set a conversion factor of "1e-6" (to convert to sqm instead of milimeters). All three windows are confirmed with OK.

 

As I'm doing that very regular it is each time quiet a few inputs to reach my goal. I'd like to optimise that.

My ideal solution would be that I select the block containing the attributes I'd like to change, type a command and are asked to select a closed contour. Other inputs are automated.

 

I'm of course able to get the entity of the selected block and use entget to get into it's regular attributes like position etc, but I struggle to access the attributes. Not to mention to modify them by macro.

 

Thank you for your support. you can't imagine how much it would mean to me to simplify that task.

Posted

Not sure if this idea is any use:

- Start the command

- Select the closed polyline (can do some stuff to check a closed polyline is selected)

- Select the block and attribute 'Area' is upated?

 

This should return the area of a closed polyline:

 

(defun Get_Area ( / )
  (setq MyEnt (car (entsel)))
  (command "._area" "_O" MyEnt)
  (getvar "area")
)

 

 

and because I do like to show that it is all online somewhere, usually in Lee Macs website; this should update an attribute (set Attribute): http://www.lee-mac.com/attributefunctions.html

Posted (edited)

Thank you for the hints.
But it looks promising. as of now. I guess the part I need to figure out more is how to put LeeMac's code to work in the correct attribute within a block. I'll give it a shot.

Edit:

Oh, LeeMac's code even includes that one. Very impressive. Somehow I didn't end up there when I was searching the internet. Thank you for pointing that one out!

Edited by Ament
Posted
2 hours ago, Ament said:

Thank you for the hints.
But it looks promising. as of now. I guess the part I need to figure out more is how to put LeeMac's code to work in the correct attribute within a block. I'll give it a shot.

Edit:

Oh, LeeMac's code even includes that one. Very impressive. Somehow I didn't end up there when I was searching the internet. Thank you for pointing that one out!

 

You're welcome  🍻

Posted
3 hours ago, Ament said:

Thank you for the hints.
But it looks promising. as of now. I guess the part I need to figure out more is how to put LeeMac's code to work in the correct attribute within a block. I'll give it a shot.

Edit:

Oh, LeeMac's code even includes that one. Very impressive. Somehow I didn't end up there when I was searching the internet. Thank you for pointing that one out!

 

Thank you, I'm pleased that the program will prove useful!

Posted (edited)
On 8/16/2023 at 11:23 AM, Lee Mac said:

 

Thank you, I'm pleased that the program will prove useful!

Unfortunately I'm running into more trouble. I also discovered your other programs to get or set values to selected blocks containing attributes.

My knowledge doesn't allow me to make them run properly.

E.g. on your program "Get Attribute Values" I'm failing to define the needed input blk correctly. I tried to use:

Command: (setq ats (entsel "\nSelect attributed block: "))
Select attributed block: (<Entity name: 218a521fe70> (7451.54 2321.72 0.0))
Command: (setq bk (vlax-ename->vla-object (car ats)))
#<VLA-OBJECT IAcadBlockReference 00000218bad59278>
Command: (LM:vl-getattributevalues ( bk ))
; error: bad function: #<VLA-OBJECT IAcadBlockReference 00000218bad59278>

But it seems that the expected input for the block is a different one. In my dispair I also tried the Entity name of the block but obviously also failed. :(
What is the expected input to the function?

 

Hm, funnily enough it works if I run the code from the function without calling it as a subroutine.

Command: (mapcar '(lambda ( att ) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke (vlax-ename->vla-object (car (entsel "\nSelect attibuted block"))) 'getattributes))
Select attibuted block(("TYPE" . "Outdoor areas") ("CATEGORY" . "Sun areas") ("Name" . "Outer Promenade") ("AREA" . "263"))

 

Edited by Ament
Enhanced information available in code section
Posted

Of course.. That was the version I didn't try. Thank you so much. Especially to not getting tired to help amateurs like me. 😅 Now it has to become so much easier to fill our attributes block and so much more efficient. 

Thank you again. 

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...