Adding textbox to inventor part sketch from within excel vba "type mismatch"

Adding textbox to inventor part sketch from within excel vba "type mismatch"

dhanna
Enthusiast Enthusiast
593 Views
0 Replies
Message 1 of 1

Adding textbox to inventor part sketch from within excel vba "type mismatch"

dhanna
Enthusiast
Enthusiast

Good morning;

 

I am writing an excel vba that will be using user defined class objects and dictionaries to grab the data on the worksheets and create the linework for the part skeletons, apply frame generated extrusions (haven't gotten that far yet), add the parameters and so on.

I've been stuck trying to add text to a planar sketch in the part file.

After many attempts, throwing things together from various examples I found in various searches, I went through the

examples in the inventor help reference and tried the sample for extruded text. 

That works when it is in inventor vba.

I modified it to work in excel by changing thisapplication to InvApp, as such:

<code>

 Public Sub ExtrudeSketchText()
 Dim InvApp As Inventor.Application
 
 Set InvApp = CreateObject("Inventor.Application") '''' added this as I am running from excel
 
    ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = InvApp.Documents.Add(kPartDocumentObject, _
                InvApp.FileManager.GetTemplateFile(kPartDocumentObject))
    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
    ' Create a new sketch on the X-Y work plane.
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))
    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = InvApp.TransientGeometry  ''''''changed all thisapplication to InvApp
    ' Create a text box at (0,0)
    Dim oTextBox As TextBox
    Set oTextBox = oSketch.TextBoxes.AddFitted(oTransGeom.CreatePoint2d(0, 0), "c:\pathinfo\somemorepath\partSkeleton.ipt") '''<<<----type mismatch here
    ' Add the text box to an object collection
    Dim oPaths As ObjectCollection
    Set oPaths = InvApp.TransientObjects.CreateObjectCollection
    oPaths.Add oTextBox
   
    ' Create a profile. Calling the AddForSolid method without any
    ' arguments will result in a profile containing all possible
    ' paths in the sketch. By passing in the text box, the profile
    ' is restricted to the input text path.
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid(False, oPaths)
    ' Extrude the text.
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent(0.25, kNegativeExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
End Sub

</code>

 

I guess it could be how I call the inventor application though this has worked for creating an assembly document and part document in a separate sub.

otherwise there might be some issue with the method being called from excel or something like that.

any suggestions would be appreciated.

 

thank you in advance.

0 Likes
594 Views
0 Replies
Replies (0)