How to grouping lines to a block?

How to grouping lines to a block?

sprtolansgz
Observer Observer
359 Views
1 Reply
Message 1 of 2

How to grouping lines to a block?

sprtolansgz
Observer
Observer

Iwant to create a square with autocad and grouping them to block. OLANSGZ

Call CreateLine(p1, p2) 'creating top line
Call CreateLine(p2, p3) 'creating right line 
Call CreateLine(p3, p4) 'creating bottom line
Call CreateLine(p4, p1) 'creating left line

Function CreateLine(firstPoint, secondPoint)
    Dim StartPoint(0 To 2) As Double
    Dim EndPoint(0 To 2) As Double
    StartPoint(0) = firstPoint(0)
    StartPoint(1) = firstPoint(1)
    StartPoint(2) = 0
    
    EndPoint(0) = secondPoint(0)
    EndPoint(1) = secondPoint(1)
    EndPoint(2) = 0
    
    With ThisDrawing.ModelSpace
    .AddLine StartPoint, EndPoint
    .Item(.Count - 1).Update
    End With
     
    
End Function

now I want grouping this square to a block with a custom name with VBA and AutoCAD. How can I do?

0 Likes
360 Views
1 Reply
Reply (1)
Message 2 of 2

Ed__Jobe
Mentor
Mentor

Model Space is just a block. Just add a block using

Dim myBlock as AcadBlock

Set myBlock = ThisDrawing.Blocks.Add(insPt, "myblock")

 

to create a block with the name you want. Then replace

ThisDrawing.ModelSpace

 

with

myBlock

Sub AddMyBlock ()
  Dim myBlock as AcadBlock
  Dim insPt(0 to 2) As Double 'default to 0,0,0
  Set myBlock = ThisDrawing.Blocks.Add(insPt, "myblock")

  With myBlock
    Dim l As AcadLine
    dim cnt As Integer
    For cnt = 0 To 3
      Set l = .AddLine(pt1, pt2) 'pt's need to be defined somewhere.
      l.Layer = "0"
    Next cnt
    .Layer = "0"
  End With
End Sub

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes