Page 1 of 1

Interacting with IntelliCAD Block Objects in VBA Causes a Crash

Posted: Thu Mar 13, 2025 3:02 pm
by oliver_xdot
I'm working on migrating a VBA project from ICAD 6 to ICAD 13. The current issue I'm facing is that any interaction with a Block object's items will cause a crash. Adding the object to the watch causes a crash, as does calling any of its methods.

I've called out the crashing line. Some things I've tried:
  • Using StnBlock.Item(1).color.SetRGB 0,0,0
  • Running as an adminstrator
  • Wrote the vic2color function, which takes the IntelliCAD "vic" index and returns a color object
    • It seems like color handling has changed dramatically since ICAD 6 and documentation is lacking
  • Added StnBlock.Item(1) to watch
    • This causes a crash; however, if I watch StnBlock, I can see the line object stored under Item
  • I'm going to try and post the code in a response on this thread. I'm getting hit by the spam filter.

Thanks in advance for any help!

Re: Interacting with IntelliCAD Block Objects in VBA Causes a Crash

Posted: Fri Mar 14, 2025 6:28 am
by oliver_xdot
A piece of the offending code, I can't post the whole Sub without getting hit by the spam filter:

Code: Select all

'set the current layer to 0 for block creation
    Doc.ActiveLayer = Doc.Layers("0")
  
    'create new Station Block----------------
    StnBlockName = "RD_" & levelGUID & "_StnBlock"
    Set StnBlock = Doc.Blocks.Add(InsertionPt, StnBlockName)
    
    ' get point coords
    Dim coord1 As Object
    Dim coord2 As Object
    
    Set coord1 = IntelliCAD.Library.CreatePoint(0, maxDia / 2 * 1.2, 0)
    Set coord2 = IntelliCAD.Library.CreatePoint(0, -maxDia / 2 * 1.2, 0)
    
    'create line for station
    'StnBlock.AddLine coord1, coord2
    
    'set line color
    StnBlock.Item(1).color = vic2color(StnBlock.Item(1).color, vicCyan)		' < ---- This is the line that crashes
    StnBlock.Item(1).Linetype = "CONTINUOUS"			' < ---- If I comment out the above line this one causes a crash, too

Re: Interacting with IntelliCAD Block Objects in VBA Causes a Crash

Posted: Fri Mar 14, 2025 8:32 am
by QuanNguyen
Hi Oliver,
There have been a lot of improvements since version 6.
You can refer to this thread viewtopic.php?t=3226&sid=07ee517340b8ea ... 3538a1a35e
or the small code below, then modify your VBA to fit your work.

Code: Select all

Public Sub ChangeProperties()
    Dim ss As SelectionSet
    Dim i As Integer
    
    For Each ss In ActiveDocument.SelectionSets
        If ss.Name = "TEMP_SSET" Then
            ss.Delete
            Exit For
        End If
    Next
    
    Set ss = ActiveDocument.SelectionSets.Add("TEMP_SSET")
    ss.SelectOnScreen
   
    If ss.Count <> 0 Then
        For i = 0 To ss.Count - 1
            ss.Item(i).color.ColorIndex = 1 ' vicRed
            ss.Item(i).Linetype = "CONTINUOUS"
            ss.Item(i).Update
        Next
    End If
End Sub

Re: Interacting with IntelliCAD Block Objects in VBA Causes a Crash

Posted: Fri Mar 14, 2025 1:15 pm
by oliver_xdot
Thanks Quan! I'll give it a try. If I get this working, I'll post the updated code block for future reference.