Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

isolate an occurrence

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
michael_marx
729 Views, 6 Replies

isolate an occurrence

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

6 REPLIES 6
Message 2 of 7

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

Message 3 of 7
michael_marx
in reply to: michael_marx

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

Message 4 of 7

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.

 

    Private Sub test( )
 
          Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
 
        Dim _invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("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
 
        Dim compOcc As ComponentOccurrence 
        For Each obj In selSet
 
            If TypeOf obj is ComponentOccurrence then            
            compOcc = obj
            If TypeOf compOcc.Definition.Document Is PartDocument Then
                Dim oCtrlDef As ControlDefinition
                'isolate
                oCtrlDef = _invApp.CommandManager.ControlDefinitions.Item("AssemblyIsolateCmd")
                oCtrlDef.Execute2(true)
 
                Dim oDoc As Document
                ' it is still assembly context. So active document is still the assembly
                'oDoc = _invApp.ActiveDocument
 
                ' get the corresponding part document.
                oDoc = compOcc.Definition.Document
 
                Dim oFilename As String
                ' because ': ' is not accepted, 
                ' you need to write a function to filter the char
 
                ' for simple test, i use the part file name
 
                'oFilename = compOcc.Name & ".stp"
                
                oFilename = oDoc.DisplayName &  ".stp"
                Dim oFilepath As String
                oFilepath = "c:\temp\"
                Dim oPathName As String
                oPathName = oFilepath & oFilename
                'export step
                Call oDoc.SaveAs(oPathName, True)
                'undo isolate
                oCtrlDef = _invApp.CommandManager.ControlDefinitions.Item("AssemblyIsolateUndoCmd")
                oCtrlDef.Execute2(true)
            End If
          End If
        Next
 
    End Sub

 

Message 5 of 7
michael_marx
in reply to: michael_marx

Hi,

 

thats exactly i want to do!

Thank you for your help.

 

Michael

Message 6 of 7

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?

Message 7 of 7

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.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report