Drawing 3D solid shapes with IntelliCAD VBA from inside Excel- draws text,lines,circles but no 3D solids like boxes

#1
I wonder if anyone has an idea what this problem could be? If anyone has an idea it would be great. Failing that, if you try to draw 3D solids from Excel, does it work for you? Or do you have a way of doing 3D solids from Excel already?

I've been trying to use the excellent code from elsewhere on this forum from inside Excel to draw boxes and text in IntelliCAD.
It draws the text but not the boxes.
When I do an audit, the message I get is this-

AcDb3dSolid(208CA), Modeling operation error:
Data stream is empty, Validation: <Invalid>, Default value is: < Removed>.


I have found by experiment that every function I can find using IntelliCAD.Solid3D gives this error. Lines, circles, 3DFace all work,

I am not able to try the code inside the CAD because the vba IDE is not activated (our computer department policy, I guess), even though the IntelliCAD library is present so I can reference it from inside Excel. My pathway to run vba is via another host like Excel.

Here is the start of the code to get the instance of IntelliCAD (this always works and is an adaption of some AutoCad instance code)-

Code: Select all

Public Sub startIcad()
   Dim doc As IntelliCAD.Document

    Dim AcAppClID As String
    AcAppClID = "ICAD.Application"
   Dim tAcObj As IntelliCAD.Application
   On Error Resume Next
   'try if AutoCAD already is started
   Set tAcObj = GetObject(, AcAppClID)
   If tAcObj Is Nothing Then
      'AutoCAD is not running or not reacting, so we create a new process
      Set tAcObj = CreateObject(AcAppClID)
   End If
   If tAcObj Is Nothing Then
      'if that failed too something not correct
   Else
   '### icad vba test area
    Call AddBoxEx2(tAcObj) 'not working
..code finishes normally after that..end if end sub etc.

The 3D routine is similar to the one posted elsewhere on this forum except it has to link to the document object a different way as we are outside the CAD application.

Code: Select all

Public Sub AddBoxEx2(tAcObj As IntelliCAD.Application)
    Dim myDoc As IntelliCAD.Document
    Dim pt As IntelliCAD.Point
    Dim t As IntelliCAD.text
    Dim s As IntelliCAD.Solid3D
    Dim i As Integer
    
    Set myDoc = tAcObj.ActiveDocument
    Set pt = Library.CreatePoint(100, 200, 0)
        
    For i = 1 To 10
        pt.y = pt.y + 125
        Set t = myDoc.ModelSpace.AddText("Hello World!", pt, 100)
        t.Color.SetRGB i * 10, i * 15, i * 20
        pt.x = pt.x - 100
        
        ' How to show box?
        Set s = myDoc.ModelSpace.AddBox(pt, 100, 100, 100)
        s.Color.SetRGB i * 10, i * 15, i * 20
        pt.x = pt.x + 100
        
    Next i
    
    ' zoom
    tAcObj.ActiveDocument.Application.ZoomExtents
    
End Sub
Thanks in advance for any ideas you have. All the best to you. R.

Re: Drawing 3D solid shapes with IntelliCAD VBA from inside Excel- draws text,lines,circles but no 3D solids like boxes

#4
Hi,
For the VBA in Excel, please use this sub

Code: Select all

Public Sub startIcad()
    Dim cadObj As Object
    
    Dim AcAppClID As String
    AcAppClID = "ICAD.Application"
    
    On Error Resume Next
    
    'try if IntelliCAD already is started
    Set cadObj = GetObject(, AcAppClID)
    
    If cadObj Is Nothing Then
        'IntelliCAD is not running or not reacting, so we create a new process
        Set cadObj = CreateObject(AcAppClID)
    End If
    
    If cadObj Is Nothing Then
        'if that failed too something not correct
    Else
        cadObj.Visible = True
        '### icad vba test area
        Call AddBoxEx(cadObj)
    End If
    
End Sub
Then

Code: Select all

Public Sub AddBoxEx(cadObj As Object)
    Dim myDoc As Object
    Dim iCadLibrary As Object
    
    Dim pt As IntelliCAD.Point
    Dim t As IntelliCAD.Text
    Dim s As IntelliCAD.Solid3D
    Dim i As Integer
    
    Set myDoc = cadObj.ActiveDocument
    Set iCadLibrary = cadObj.Library
    Set pt = iCadLibrary.CreatePoint(100, 200, 0)
    
...    
    

Re: Drawing 3D solid shapes with IntelliCAD VBA from inside Excel- draws text,lines,circles but no 3D solids like boxes

#5
Hello there, thanks for the update.

I am beginning to think your code is fine and the problem is at my end.

My only change to your code was to open a file name before setting the active document, but I think it is due to the following point.

When I run your code I get the text and not the boxes as before, but I have noticed it is putting them on a new layer that was not in the drawing previously.

This layer is predefined in a bolt on modification that our computer department have added, so I think it is affecting the VBA commands via COM from Excel.

That is so annoying.

I need to look into this, but without your help I would not be investigating this route so thank you so much for that.

I have access to the installation files. There are no files listed under APPLOAD. I've edited the ACAD.LSP and some other lisp files but it still seems to be loading. The command line says this (XXXX is the bolt on name but it is internal so is no help in solving the problem)

XXXX is loaded (Loading Time: 9.856)
Command:


The other route I have tried, which does work but was my backup, is to generate a text file in XL (which I have called BONGO.TXT) and run that on the command line as a script file. The script file is in lisp.

Do you by any chance know how to run the script file using VBA? Maybe that will work better.

The command line functions I use to run it now is this (this is as defined in the CUI)-

(command "_.script" "D:\\LC\\CAD Custom\\BONGO.TXT")

Thanks for all your help,
R,

Re: Drawing 3D solid shapes with IntelliCAD VBA from inside Excel- draws text,lines,circles but no 3D solids like boxes

#6
Hi,

First, we're talking about the IntelliCAD, not AutoCAD.

And the script command requests a file with the extension scr, (not .txt as you wrote).

Here is the code to call the command in VBA for excel:

Code: Select all

Public Sub SendCommandEx(iCadApp As Object)

    '(command "_.script" "C:\\IntelliCAD\\BONGO.txt")
    iCadApp.ActiveDocument.SendCommand ("_.script" & vbCr & "C:\\IntelliCAD\\BONGO.scr" & vbCr)
    
End Sub

Code: Select all

Public Sub MainIcad()
    Dim cadObj As Object
    
    Dim AcAppClID As String
    AcAppClID = "ICAD.Application"
    
    On Error Resume Next
    
    'try if IntelliCAD already is started
    Set cadObj = GetObject(, AcAppClID)
    
    If cadObj Is Nothing Then
        'IntelliCAD is not running or not reacting, so we create a new process
        Set cadObj = CreateObject(AcAppClID)
    End If
    
    If cadObj Is Nothing Then
        'if that failed too something not correct
    Else
        cadObj.Visible = True
        '### icad vba test area
        'Call AddBoxEx(cadObj)
        Call SendCommandEx(cadObj)
    End If
    
End Sub

Re: Drawing 3D solid shapes with IntelliCAD VBA from inside Excel- draws text,lines,circles but no 3D solids like boxes

#7
That is wonderful, thank you.

You are correct- scr is the normal script suffix. I use txt (and ICAD allows it) as up to now the lisp files have been edited in Notepad. But when they are made in Excel no reason not to use scr when the text files are correct.

I've put the code below in case it helps anyone else, but it is not significantly different to your post..

An alternative to using a script is to port the lisp line by line to the command prompt using the send command- but I think I will stick to a script as then I have an automatic record of the last commands I send to ICAD.

Thanks again,
R.

Code: Select all

Public Sub RunScript(iCadApp As Object, sScriptFile As String)
iCadApp.ActiveDocument.SendCommand ("_.script" & vbCr & "D:\\LC\\CAD Custom\\" & sScriptFile & vbCr)
End Sub

Public Function OpenICAD(iCadApp As Object) As Boolean
OpenICAD = False
    Dim sICADApp As String
    sICADApp = "ICAD.Application"
    On Error Resume Next
    'try if IntelliCAD already is started
    Set iCadApp = GetObject(, sICADApp)
    If iCadApp Is Nothing Then
        'IntelliCAD is not running or not reacting, so we create a new process
        Set iCadApp = CreateObject(sICADApp)
    End If
    
    If iCadApp Is Nothing Then
        'if that failed too something not correct- leave as false
    Else
        iCadApp.Visible = True 'never want CAD in background if open
        OpenICAD = True
    End If
End Function

Public Sub OpenIcadRunScript()
    Dim iCadApp As Object
    If OpenICAD(iCadApp) Then
        On Error Resume Next 'if already open gives error- this is a temporary fix until add check for open filenames
        Call iCadApp.Documents.Open("D:\LC\W17 All\W17 CAD" & "\" & "Template.dwg", False)
        Call RunScript(iCadApp, "BONGO.txt")
    Else
        MsgBox "CAN not able to start."
    End If
End Sub