Adding textbox to inventor part sketch from within excel vba "type mismatch"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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>
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))
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))
Dim oTransGeom As TransientGeometry
Set oTransGeom = InvApp.TransientGeometry ''''''changed all thisapplication to InvApp
Dim oTextBox As TextBox
Set oTextBox = oSketch.TextBoxes.AddFitted(oTransGeom.CreatePoint2d(0, 0), "c:\pathinfo\somemorepath\partSkeleton.ipt") '''<<<----type mismatch here
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)
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.