How to grouping lines to a block?

How to grouping lines to a block?

m09366023695
Enthusiast Enthusiast
303 Views
1 Reply
Message 1 of 2

How to grouping lines to a block?

m09366023695
Enthusiast
Enthusiast

I want to create a square with autocad and grouping them to a block.

 

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

 

and my function:

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
304 Views
1 Reply
Reply (1)
Message 2 of 2

seabrahenrique
Advocate
Advocate

Well,

 

Have u consider to use the creation of lines direct on the block? Like that:

 

Sub CreateSquareAndFormBlock()

    '0 Declarations and variables
    Dim blockName As String, insPt(0 To 2) As Double, Line As AcadLine, MyBlock As AcadBlock
    Dim p1(0 To 2) As Double, p2(0 To 2) As Double, p3(0 To 2) As Double, p4(0 To 2) As Double
    blockName = "NewBlock"

    'Form your square
    p2(0) = 10: p2(0) = 10:  p3(0) = 10: p3(1) = 10: p4(1) = 10

    'Create a new block
    Set MyBlock = ThisDrawing.Blocks.Add(insPt, blockName)

    'ADD LINES DIRECT ON YOUR BLOCK
    MyBlock.AddLine p1, p2
    MyBlock.AddLine p2, p3
    MyBlock.AddLine p3, p4
    MyBlock.AddLine p4, p1

    'Add the blockreference in model space
    ThisDrawing.ModelSpace.InsertBlock insPt, blockName, 1, 1, 1, 0

End Sub

 

I guess this is a more simples way to do your propose.

 

But if you really want to do a lines by a function, so, consider to transform your function in a Line typed function like that:

 

Function CreateLine(firstPoint, secondPoint) As AcadLine 'Diference one

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
Set CreateLine = .AddLine(StartPoint, EndPoint) 'Diference two
.Item(.Count - 1).Update
End With

End Function

 

And then you also can Add a created line by your function in a block, got it?

 

(But i guess the first way is more simple and better)

 

Hope can help u!

0 Likes