How to get the perimeter of drawing is a polyline inside on block

How to get the perimeter of drawing is a polyline inside on block

Anonymous
Not applicable
1,028 Views
5 Replies
Message 1 of 6

How to get the perimeter of drawing is a polyline inside on block

Anonymous
Not applicable
The drawing have a perimeter defined by a polyline all the drawing are inside on block.

How can I get the polyline as object or entity or polyline, I need the object.

I need a VBA code for do this

Thanks Edited by: Zeusovsky on Feb 24, 2009 5:52 PM
0 Likes
1,029 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Would like to help if i could understand the question.
What block are you talking about? ActiveLayout.Block?
Get the ActivePViewport, get it's Handle, then use LISP, sorry I do not know other way.
SendCommand("(defun DXF ( / num ed) (cdr (assoc num ed))) & vbCr ") { = shortcut}
SendCommand("(setq e (dxf 340 (entget (handent "& chr(34) & Handle & chr(34) & )))) & vbCr")
This will give the entity.
Next trick: SendCommand("(setvar "USERS1" (dxf 5 (entget e))) & vbCr")
The vbCr is equivalent to Return/Enter; chr(34) = "
Now you gan get the handle (H2) of the associated object with GetVariable("USERS1"),
Dim ent as AcadEntity
set ent = HandleToObject(H2)
I cannot find a direct method in VBA.

Edited by: lucaso on Feb 25, 2009 12:33 AM Edited by: lucaso on Feb 25, 2009 12:35 AM
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thanks very much for your help 🙂

I belive it's block reference or block definition, I have not sure.
But maybe if I tell you How I create the block

in command prompt write
Block
Then appeared window Block Definition
I put the name, select the pick point and select all the objects on the drawing and press ok

So if we review the drawing structure is like this:

Block...more deep or inside ...Polyline...more deep or inside ..... are all the objects (circles, lines, arcs....)

Block
Polyline (The perimeter of drawing)
Acad Objects(Circles, lines, text, arcs)

Do you understand me?

I need obtain the polyline with VBA code o other method but by code Edited by: Zeusovsky on Feb 24, 2009 11:45 PM
0 Likes
Message 4 of 6

Anonymous
Not applicable
hi, I think I understand now, you are making a regular (normal) block. Before making a block put 'perimeter' n a separate layer or give it a special colour. When you make a block you give it a name. My quess is that you work in Modelspae.
Public Sub FindPeri()
Dim ent as AcadEntity
Dim blref as AcadBlockReference
Dim bl as AcadBlock
Dim obj as AcadObject
for each obj in thisdrawing.ModelSpace ''<--Modelspace otherwise Thisdrawing.Paperspace
if obj.objectname = "AcDbBlockReference" then set blref=obj
set bl = Thisdrawing.Blocks(blref.Name)
for each ent in bl '''walk through the block-definition
if ent.Layer="PERI-LAYER" [ or ent.Colour=PERI-COLOUR ]
'----- Do Your Thing --------
end if
next 'bl
next 'blref
end sub

Hope I understood Edited by: lucaso on Feb 25, 2009 2:38 AM
0 Likes
Message 5 of 6

Anonymous
Not applicable
It's a drawing and I do it a block, I using different layers. The polyline must be on layer "PERIMETROS" .The objective of the program is detect if the polyline layer Because I have too much drawings for review.

If the perimeter (polyline) is not on layer"PERIMETROS" , then I need to change it. to layer "PERIMETROS".

The drawing is on Model Space Edited by: Zeusovsky on Feb 25, 2009 4:15 PM
0 Likes
Message 6 of 6

Anonymous
Not applicable
looks to me as you have a real problem: the only perimeter I can think off in your drawing will have no bulges (no arcs)
you could test all the polylines you find, if it has a bulge. You will need to traverse the polyline-vertices to find one, if found it is not your perimeter! But is it not easier to create a perimeter using Blref.GetBoundingbox minpt, maxpt?
You can construct a polyline-rectangle with those points: minpt(0), minpt(1) / maxpt(0),minpt(1) / maxpt(0), maxpt(1) / minpt(0), maxpt(1) and then close it. It will give you a nice cleanfitting rectangle around your block. Then place it on the wanted layer. Check if you have the layer, otherwise create it first.
0 Likes