VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reg. Z CoOrdinates Required While Inserting Block

4 REPLIES 4
Reply
Message 1 of 5
dhimant.bhensdadia
326 Views, 4 Replies

Reg. Z CoOrdinates Required While Inserting Block

Sub Example_InsertBlock()
    ' This example creates a block containing a circle.
    ' It then inserts the block.

    ' Create the block
    Dim blockObj As AcadBlock
    Dim insertionPnt(0 To 2) As Double
    insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
    Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "CircleBlock")
    
    ' Add a circle to the block
    Dim circleObj As AcadCircle
    Dim center(0 To 2) As Double
    Dim radius As Double
    center(0) = 0: center(1) = 0: center(2) = 0
    radius = 1
    Set circleObj = blockObj.AddCircle(center, radius)
   
    ' Insert the block
    Dim blockRefObj As AcadBlockReference
    insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
    
    ZoomAll
    
End Sub

 

---------------------------------------------------------------------------------------------------------------------------------------------

 

This is the code for inserting block in the Model Space using COM API. In that you can ssee that while inserting block
we have to use array of double of size 3 insertionPnt(0 to 2)

 

So my question is while working with 2D, why 3rd CoOrdinate (Z-Coordinate) required ?
Let me correct If I am wrong then the need of double array of size 3 becuase we have 3 CoOrdinate (X,Y,Z) right ?

4 REPLIES 4
Message 2 of 5

Does not matter you work 2d or 3d Autocad recognize a point X,Y and Z axis. You need to give as an input even if 0.

Message 3 of 5

Ok Agree but what is the reason behind this ?
Message 4 of 5

You may want to insert block a different Z you can use it. A developer must consider all choices that the user needs. If it is different in case of 2d and 3d it has more complicate to who use COM API. And also it is opposite to general programming logic because more met...

Message 5 of 5

There is no such thing as "2D" in AutoCAD (outside of LWPOLYLINE objects).  All coordinates are stored as three values (X Y Z).  If there was a separate "2D space" then the programming has to be that much more complex to handle both systems instead of just one.  Much easier, faster, fewer problems, etc. to use the same methods for both ways.

 

If its that much of a bother, you can always write your own "2D" methods which assume a Z-value of 0 and call those instead of the root AutoCAD ones.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost