Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

oDerivedCommandDef.Execute without dialog box

shastu
Advisor

oDerivedCommandDef.Execute without dialog box

shastu
Advisor
Advisor

When I use the oDerivedCommandDef.Execute code in my vba how do I get past the dialog box.  I would be fine if the dialog box didn't come up at all because I need to do things after the derive.

0 Likes
Reply
551 Views
3 Replies
Replies (3)

DRoam
Mentor
Mentor

Which control definition are you executing? "oDerivedCommandDef" is just an instance of a ControlDefinition object that was probably created using something like:

 

 

Dim oDerivedCommandDef As ControlDefinition
oDerivedCommandDef = ThisApplication.CommandManager.ControlDefinitions.Item("<Control Definition Name>")

 

There's no way to know what you're trying to do from the arbitrary name (in this case "oDerivedCommandDef") that was given to the Control Definition object. So what is the actual <Control Definition Name> in your case?

 

I ask because I would guess (and hope) that whatever derive operation you're doing could be done directly via the API, rather than by executing a user command.

 

Most Control Definitions execute some kind of user command which by it nature requires user input to complete, and in some case there's no way to provide those inputs automatically. But there's no way to say without knowing what exactly you're trying to do.

0 Likes

DRoam
Mentor
Mentor

Did some searching and found this thread where someone uses the same "oDerivedCommandDef" definition to execute the "PartDerivedComponentCmd" command. So it looks like you're just trying to derive a component into a Part.

 

To do this via the command manager, you just need to post a "private event" before executing the command to let Inventor know which file to Derive in. You can do so like this:

 

oFileName = "C:\path\file.ipt"

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFileName)

Dim oDerivedCommandDef As ControlDefinition
oDerivedCommandDef = ThisApplication.CommandManager.ControlDefinitions.Item("PartDerivedComponentCmd")
oDerivedCommandDef.Execute

However, this can also be done directly via the API instead, and I would strongly recommend doing so. It's more stable and will give you better control as well. Here's the code for that:

 

oFileName = "C:\path\file.ipt"

Dim oPartDoc As Inventor.PartDocument = ThisDoc.Document
Dim oPartDef As Inventor.PartComponentDefinition = oPartDoc.ComponentDefinition

Dim oDerivedPartDef As Inventor.DerivedPartUniformScaleDef
oDerivedPartDef = oPartDef.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oFileName)
'See API help for how to set additional options for the DerivedPartUniformScaleDef

Dim oDerivedPartComponent As Inventor.DerivedPartComponent
oDerivedPartComponent = oPartDef.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef)
'See API help for how to perform additional edits to the DerivedPartComponent after it's been created

Here's a link to the API help for the "DerivedPartUniformScaleDef" object: Inventor API Help: DerivedPartUniformScaleDef Object. You can use the methods and properties shown here to have much more control over the Derive operation than using the Command Manager would give you.

 

And here's a link to the API help for the "DerivedPartComponent" object: Inventor API Help: DerivedPartComponent Object. You can use the methods and properties shown here to edit the Derive feature even after it's been created.

 

Both ways give you about the same options, but I would guess that editing the "DerivedPartComponent" after-the-fact would allow you to access specific features within the Derived component, while the DerivedPartUniformScaleDef would not, as it doesn't have any details about the specific component yet.

 

Hope this helps.

shastu
Advisor
Advisor

Dim oApp As Application
 Dim oCurrentDoc As Document
 Dim oNewDoc As Document
 Dim UseDefaultTemplate As Boolean
 Dim sCurrentFileName As String
 Dim sTemplatePart As String
 Set oApp = ThisApplication
 Set oCurrentDoc = oApp.ActiveDocument
 Select Case oApp.ActiveDocumentType
 Case kAssemblyDocumentObject, kPartDocumentObject
sCurrentFileName = ThisApplication.ActiveDocument.FullFileName
If sCurrentFileName = "" Then
MsgBox "The active file must first be saved"
Exit Sub
End If
'if you want to use the default template then set UseDefaultTemaplte = True
'if you want to use a custom template set the path and filename of sTemplatePart and UseDefaultTemaplte = False
UseDefaultTemplate = False
sTemplatePart = "Q:\Inventor\Templates_v2017\part.ipt"
Select Case UseDefaultTemplate
Case True
Set oNewDoc = oApp.Documents.Add(kPartDocumentObject)
Case False
Set oNewDoc = oApp.Documents.Add(kPartDocumentObject, sTemplatePart, True)
End Select
 '******START UPDATED CODE **************
 'If your template has an active sketch you need to close it.
Dim oSketch As Sketch
On Error Resume Next
Set oSketch = oNewDoc.ComponentDefinition.Sketches.Item(1)
oSketch.ExitEdit
On Error GoTo 0
 '******END UPDATED CODE **************
'Get the control definition that represents the derived part command.
Dim oDerivedCommandDef As ControlDefinition
Set oDerivedCommandDef = ThisApplication.CommandManager.ControlDefinitions.Item("PartDerivedComponentCmd")
'Post the filename to the private event queue.
Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, sCurrentFileName)
'Start the derived part command.
oDerivedCommandDef.Execute
 Case Else
MsgBox "You must first have a Part or Assembly document open"
 End Select

0 Likes