Hi
i don´t find a way to isolate and undo isolate an occurrence in Assembly can anybody help me wih the right code in VB.
regards Michael
Solved! Go to Solution.
Solved by xiaodong_liang. Go to Solution.
hi,
I did not fine a direct property to toggle [isolate] or [undo isolate]. But you could select the occurrence and execute the commands .e.g
Sub isolate_undoisolate()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence
Set oOcc = oDoc.ComponentDefinition.Occurrences.Item(1)
oDoc.SelectSet.Clear
oDoc.SelectSet.Select oOcc
Dim oCtrlDef As ControlDefinition
'isolate
Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyIsolateCmd")
'undo isolate
'Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyIsolateUndoCmd")
oCtrlDef.Execute
oDoc.SelectSet.Clear
End Sub
hi
Thank you for your reply, but no i have another issue.
Problem description i want to iterate through a select set of occurrences and each occurrence should isolated saved as stp from within the the top assembly with occurrence name.
first problem is the occurence name. with compocc.name & ".stp" i think i get the name with stp file extension but something went wrong i get a file with the right name but no extension?!?
second problem is the iteration through the select set but i don´t know why.
Sorry for my miserable programming but i´m a newbie to this 🙂
Dim _invApp As Inventor.Application
If _invApp.Documents.Count = 0 Then
MsgBox("Need to open an Assembly document")
Return
End If
If _invApp.ActiveDocument.DocumentType <> _
DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("Need to have an Assembly document active")
Return
End If
Dim asmDoc As AssemblyDocument
asmDoc = _invApp.ActiveDocument
If asmDoc.SelectSet.Count = 0 Then
MsgBox("Need to select a Part or Sub Assembly")
Return
End If
Dim selSet As SelectSet
selSet = asmDoc.SelectSet
For Each obj In selSet
compOcc = obj
If TypeOf compOcc.Definition.Document Is PartDocument Then
Dim oCtrlDef As ControlDefinition
'isolate
oCtrlDef = _invApp.CommandManager.ControlDefinitions.Item("AssemblyIsolateCmd")
oCtrlDef.Execute()
Dim oDoc As Document
oDoc = _invApp.ActiveDocument
Dim oFilename As String
oFilename = compOcc.Name & ".stp"
Dim oFilepath As String
oFilepath = "d:\temp\"
Dim oPathName As String
oPathName = oFilepath & oFilename
'export step
Call oDoc.SaveAs(oPathName, True)
'undo isolate
oCtrlDef = _invApp.CommandManager.ControlDefinitions.Item("AssemblyIsolateUndoCmd")
oCtrlDef.Execute()
End If
Next
two issues here:
1) the occurrence name contains ‘ : ‘, which is not accepted as a char in file name. This is Windows rule. So e.g.
myPart:1.stp is truncated as myPart.
That is why you saw the file name without extension name. And the file size is 0
2) ControlDefiniton.Execute is Post Command (asynchronously). That means it will be executed after the function which invokes it. So to Send Command (Synchronous), you need to use Execute2(true)
Please refer to the code below. note: you will need to write a method youeself to filter the invalid chars before saving.
I tried the exact same code in Inventor 2015. The parts get selected but the isolation process does not thing.
Is this obsolete in 2015?
I found the problem with my code.
The trick with using any of the execute command in Inventor is that, if my form is still open, Inventor doesn't execute the command.
So, I ended up making the form invisible , running te command and then show the form back.