block with a closed 3d poly from excel

block with a closed 3d poly from excel

hashemian
Contributor Contributor
504 Views
5 Replies
Message 1 of 6

block with a closed 3d poly from excel

hashemian
Contributor
Contributor

I am trying to create a block which contains a closed 3d polyline from excel and my code is not working.

also how can I draw this polyline with a different color like yellow instead of default color?
Thanks.

 

 

 

Option Explicit

Sub Button1_Click()

Dim acad As AcadApplication
Set acad = GetObject(, "Autocad.Application")
Dim adoc As AcadDocument
Set adoc = acad.ActiveDocument


Dim blocka As AcadBlock
Set blocka = adoc.ActiveLayout.Block
Dim strname As String

Dim pol(0 To 8) As Double
Dim origin(2) As Double

Dim t As Acad3DPolyline

origin(0) = 0: origin(1) = 0: origin(2) = 0


pol(0) = 0: pol(1) = 100: pol(2) = 200
pol(3) = -100: pol(4) = 130: pol(5) = 250
pol(6) = 100: pol(7) = 230: pol(8) = 350

Set t = adoc.ModelSpace.Add3DPoly(pol)
t.Closed = True

strname = "myblock"

    
    
    Set blocka = adoc.Blocks.Add(origin, strname)
    blocka.Add3DPoly (t)
     
    
End Sub

0 Likes
505 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> my code is not working

Describe that please a bit more detailed, what does not work? Do you get an exception? If yes, which one and at which code line.

Or everything runs well, no error message, but nothing to see (have you zoomed close enough, is at least the 3D-Poly created, ...)

 

It's easier to help when we know where to start!

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 6

hashemian
Contributor
Contributor

Thanks for your reply.. sorry for not being clear.

The error that I am getting is "run time error 438" object doesn't support this property or method.

If I change my code to this, it will work but as soon as I try to close my polyline it will not work I think my error is where I am trying to close it..

Thanks again..

here is the working code:

 

Option Explicit

Sub Button1_Click()

Dim acad As AcadApplication
Set acad = GetObject(, "Autocad.Application")
Dim adoc As AcadDocument
Set adoc = acad.ActiveDocument


Dim blocka As AcadBlock
Set blocka = adoc.ActiveLayout.Block
Dim strname As String

Dim pol(0 To 8) As Double
Dim origin(2) As Double



origin(0) = 0: origin(1) = 0: origin(2) = 0


pol(0) = 0: pol(1) = 100: pol(2) = 200
pol(3) = -100: pol(4) = 130: pol(5) = 250
pol(6) = 100: pol(7) = 230: pol(8) = 350



strname = "myblock"

    
    
    Set blocka = adoc.Blocks.Add(origin, strname)
    blocka.Add3DPoly (pol)
     
    
End Sub

0 Likes
Message 4 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I think my error is where I am trying to close it

There is no line in your code which makes the polyline closed.

 

Try to change the last lines to:

Dim tPoly As Acad3DPolyline
Set tPoly = blocka.Add3DPoly(pol)
tPoly.Closed = True

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 6

hashemian
Contributor
Contributor

Thanks for your help. one more question.

How can I draw this polyline in a different color (for example yellow)?
Thanks again

 

0 Likes
Message 6 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> How can I draw this polyline in a different color

Looking to the help you'll find >>>this sample<<< for how to change colors of an entity.

In case of colors of entities within a block don't forget the special situations with color=bylayer when on layer "0" or the special color assignment "byBlock".

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes