How to use the AddExtrudedSolid method?

#1
Hi everyone,
I am trying AddExtrudedSolid method and hope to draw a 10*10*10 cube
but when the programe goes on the AddExtrudedSolid method line
It crashed
here is my code

Code: Select all

Sub try_AddExtrudedSolid()

'Declare
'Long
Dim i As Long
'Line
Dim ActLine As IntelliCAD.Line
'Collection
Dim EdgeClctn As New Collection
'Entity
Dim Edges() As IntelliCAD.Entity
'Solid3D
Dim solidObj As IntelliCAD.Solid3D
'Variant
Dim regionObj As Variant

'Code Zone
'set Edges
EdgeClctn.Add Library.CreatePoint(0, 0, 0)
EdgeClctn.Add Library.CreatePoint(0, 10, 0)
EdgeClctn.Add Library.CreatePoint(10, 10, 0)
EdgeClctn.Add Library.CreatePoint(10, 0, 0)

'Draw Curves
ReDim Edges(0 To EdgeClctn.Count - 1)
For i = 1 To EdgeClctn.Count - 1
    Set ActLine = ActiveDocument.ModelSpace.AddLine(EdgeClctn(i), EdgeClctn(i + 1))
    Set Edges(i - 1) = ActLine
Next i

Set ActLine = ActiveDocument.ModelSpace.AddLine(EdgeClctn(i), EdgeClctn(1))
Set Edges(i - 1) = ActLine

'Draw Region
regionObj = ActiveDocument.ModelSpace.AddRegion(Edges)

' Create the solid
Set solidObj = ActiveDocument.ModelSpace.AddExtrudedSolid(regionObj(0), 10, 0) ''' Here is the crash point!
regionObj(0).Delete

End Sub


Can someone help me to find out the mistake or provid me some sample about the AddExtrudedSolid method?
Any help with this is appreciated.
Thank you.

Re: How to use the AddExtrudedSolid method?

#2
Hi,
Maybe something is wrong with AddRegion, it works if the user selects an existing region.

Code: Select all

Sub try_AddExtrudedSolid()
    ' get the entity.
    Dim ent As Entity
    Dim reg As Region
    Dim pt As Point
    
    Dim solidObj As IntelliCAD.Solid3D
    
    ActiveDocument.Utility.GetEntity ent, pt, "Select Entity"
    If ent.EntityType = vicRegion Then
        Set reg = ent
        Set solidObj = ActiveDocument.ModelSpace.AddExtrudedSolid(reg, 10, 0)
    End If
End Sub

Re: How to use the AddExtrudedSolid method?

#3
QuanNguyen wrote:
Mon Oct 21, 2024 7:40 am
Hi,
Maybe something is wrong with AddRegion, it works if the user selects an existing region.

Code: Select all

Sub try_AddExtrudedSolid()
    ' get the entity.
    Dim ent As Entity
    Dim reg As Region
    Dim pt As Point
    
    Dim solidObj As IntelliCAD.Solid3D
    
    ActiveDocument.Utility.GetEntity ent, pt, "Select Entity"
    If ent.EntityType = vicRegion Then
        Set reg = ent
        Set solidObj = ActiveDocument.ModelSpace.AddExtrudedSolid(reg, 10, 0)
    End If
End Sub
Thank you Quan,
I tried your code and it works,
but here is another question,
what is the right way to use the AddRegion method in intellicad?
My code about AddRegion is copied from internet somewhere used in Autocad,
and I can't find any example about AddRegion method in Intellicad.
Can you give me some help?
Appreciate your help very much!!

Re: How to use the AddExtrudedSolid method?

#4
Hi Verdant,
While waiting for feedback from the support team, try using the last entity in the drawing instead.

Code: Select all

Sub try_AddExtrudedSolid()
    'Declare
    'Long
    Dim i As Long
    'Line
    Dim ActLine As IntelliCAD.Line
    'Collection
    Dim EdgeClctn As New Collection
    'Entity
    Dim Edges() As IntelliCAD.Entity
    'Solid3D
    Dim solidObj As IntelliCAD.Solid3D    
    'Code Zone
    'set Edges
    EdgeClctn.Add Library.CreatePoint(0, 0, 0)
    EdgeClctn.Add Library.CreatePoint(0, 10, 0)
    EdgeClctn.Add Library.CreatePoint(10, 10, 0)
    EdgeClctn.Add Library.CreatePoint(10, 0, 0)   

    'Draw Curves
    ReDim Edges(0 To EdgeClctn.Count - 1)
    For i = 1 To EdgeClctn.Count - 1
        Set ActLine = ActiveDocument.ModelSpace.AddLine(EdgeClctn(i), EdgeClctn(i + 1))
        Set Edges(i - 1) = ActLine
    Next i
    
    Set ActLine = ActiveDocument.ModelSpace.AddLine(EdgeClctn(i), EdgeClctn(1))
    Set Edges(i - 1) = ActLine
    
    'Draw Region
    ActiveDocument.ModelSpace.AddRegion (Edges)

    ' Add Solid
    Dim entLast As Entity
    Set entLast = ActiveDocument.ModelSpace.Item(ActiveDocument.ModelSpace.Count - 1)
    If entLast.EntityType = vicRegion Then
        Set reg = entLast
        Set solidObj = ActiveDocument.ModelSpace.AddExtrudedSolid(reg, 10, 0)
    End If
End Sub

Re: How to use the AddExtrudedSolid method?

#5
QuanNguyen wrote:
Tue Oct 22, 2024 1:48 am
Hi Verdant,
While waiting for feedback from the support team, try using the last entity in the drawing instead.

Code: Select all

Sub try_AddExtrudedSolid()
    'Declare
    'Long
    Dim i As Long
    'Line
    Dim ActLine As IntelliCAD.Line
    'Collection
    Dim EdgeClctn As New Collection
    'Entity
    Dim Edges() As IntelliCAD.Entity
    'Solid3D
    Dim solidObj As IntelliCAD.Solid3D    
    'Code Zone
    'set Edges
    EdgeClctn.Add Library.CreatePoint(0, 0, 0)
    EdgeClctn.Add Library.CreatePoint(0, 10, 0)
    EdgeClctn.Add Library.CreatePoint(10, 10, 0)
    EdgeClctn.Add Library.CreatePoint(10, 0, 0)   

    'Draw Curves
    ReDim Edges(0 To EdgeClctn.Count - 1)
    For i = 1 To EdgeClctn.Count - 1
        Set ActLine = ActiveDocument.ModelSpace.AddLine(EdgeClctn(i), EdgeClctn(i + 1))
        Set Edges(i - 1) = ActLine
    Next i
    
    Set ActLine = ActiveDocument.ModelSpace.AddLine(EdgeClctn(i), EdgeClctn(1))
    Set Edges(i - 1) = ActLine
    
    'Draw Region
    ActiveDocument.ModelSpace.AddRegion (Edges)

    ' Add Solid
    Dim entLast As Entity
    Set entLast = ActiveDocument.ModelSpace.Item(ActiveDocument.ModelSpace.Count - 1)
    If entLast.EntityType = vicRegion Then
        Set reg = entLast
        Set solidObj = ActiveDocument.ModelSpace.AddExtrudedSolid(reg, 10, 0)
    End If
End Sub
Thank you!! it's works
I will figure out how to rewrite by using your code.
I truly appreciate your kindness and help.

Re: How to use the AddExtrudedSolid method?

#6
The crash likely happens because regionObj(0) is invalid or AddRegion didn't create a proper region. Make sure the lines form a closed, planar loop, and add a check to confirm regionObj(0) is not Nothing before extruding. Also, try using a small taper angle like 0.01 to avoid errors . Let me know if you need a quick fix script!