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: 

Open Part directly from Assembley in new window

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
damjan_baraga
336 Views, 9 Replies

Open Part directly from Assembley in new window

 I'd like to make a rule to open Part directly from the Assembly. It must be opened in a new window to make rules continuing to the next step (for ex. i'd like to make part from Standard part to Sheet metal) 

I made 

 

Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.")
If oOcc Is Nothing Then
	MsgBox("You did not select anything. Exiting.", , "")
	Exit Sub
Else
	MsgBox("You selected an assembly occurrrence named " & oOcc.Name & ".ipt")	
End If
	
Try
	ThisDoc.Launch(Component.InventorComponent(oOcc).Definition.Document.FullFileName)
Catch
	MsgBox("File has not been saved or other issue opening file occurred")
	Exit Sub
End Try

 I made start, but then I get error in line

 

	ThisDoc.Launch(Component.InventorComponent(oOcc).Definition.Document.FullFileName)
9 REPLIES 9
Message 2 of 10

Hi @damjan_baraga ,

 

This should work for you:

 

Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.")
If oOcc Is Nothing Then
	MsgBox("You did not select anything. Exiting.", , "")
	Exit Sub
Else
	Dim oDoc As Document = oOcc.Definition.Document
	ThisApplication.Documents.Open(oDoc.FullFileName)
End If

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Message 3 of 10

Thanks. Working.
Message 4 of 10

After I put whole rule I get error in same line.

The whole rule is:

Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.")
If oOcc Is Nothing Then
	MsgBox("You did not select anything. Exiting.", , "")
	Exit Sub
Else
	Dim oDoc As Document = oOcc.Definition.Document
	ThisApplication.Documents.Open(oDoc.FullFileName)
End If


    Dim PartDoc As PartDocument
     PartDoc = ThisApplication.ActiveDocument
       
        ' Convert it to a sheet metal type.
        PartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
        
        Dim smDef As SheetMetalComponentDefinition
         smDef = PartDoc.ComponentDefinition
        
        ' Unfold the part.  This will activate the flat pattern environment.
        smDef.Unfold
        
        ' Exit the flat pattern environment.
        smDef.FlatPattern.ExitEdit
        
 
'On Error Resume Next
'Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
'Dim CadlineSheetMetal As SheetMetalComponentDefinition
CadlineSheetMetal = oDoc.ComponentDefinition
'CadlineSheetMetal.FlatPattern.Delete
CadlineSheetMetal.Unfold
Cadline = ThisApplication.ActiveDocument.ComponentDefinition
X= 10*( Cadline.RangeBox.MaxPoint.X - Cadline.RangeBox.MinPoint.X)
Y= 10*( Cadline.RangeBox.MaxPoint.Y - Cadline.RangeBox.MinPoint.Y)
Z= 10*( Cadline.RangeBox.MaxPoint.Z - Cadline.RangeBox.MinPoint.Z)
Parameter.Quiet = True
THICKNESS = MinOfMany(X, Y, Z)

ThisDoc.Document.ComponentDefinition.UseSheetMetalStyleThickness = False

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

Dim oSheetMetalCompDef As SheetMetalComponentDefinition
oSheetMetalCompDef = oPartDoc.ComponentDefinition

Dim oThicknessParam As Parameter
oThicknessParam = oSheetMetalCompDef.Thickness
oThicknessParam.Value = THICKNESS/10
'oPartDoc.Update



LENGTH = MaxOfMany(X, Y, Z)
If X < LENGTH Then
WIDTH = X
End If
If Y < LENGTH Then
WIDTH = Y
End If
If Z < LENGTH Then
WIDTH = Y
End If
iProperties.Value("Custom", "LENGTH") = Round(LENGTH, 1)
iProperties.Value("Custom", "WIDTH") = Round(WIDTH, 1)
iProperties.Value("Custom", "THICKNESS") = Round(THICKNESS, 1)

iProperties.Value("Project", "Authority") = iProperties.Value("Custom", "THICKNESS")
iProperties.Value("Summary", "Comments") = "laser"
RuleParametersOutput()
iLogicVb.UpdateWhenDone = True
oDoc = ThisApplication.ActiveDocument
CadlineSheetMetal = oDoc.ComponentDefinition
InventorVb.DocumentUpdate()



'set iproperty to use ISO view on save
oDoc.SetThumbnailSaveOption _
(ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)

oDoc = ThisApplication.ActiveEditDocument

'get current colorcheme name 
oColorScheme = ThisApplication.ActiveColorScheme.Name

'Change to Presentation
ThisApplication.ColorSchemes.Item("Presentation").Activate
ThisApplication.ColorSchemes.BackgroundType = 52737

'set iproperty to use ISO view on save
oDoc.SetThumbnailSaveOption _
(ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)




ThisDoc.Save
'Change back to original scheme
ThisApplication.ColorSchemes.Item(oColorScheme).Activate 

Call PartDoc.Close(True)

 The rule works without your add. This I get:

damjan_baraga_0-1716232390706.png

 

Message 5 of 10

Hi @damjan_baraga 

 

Here is an updated version of your code.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "'Select an assembly occurrence.")

If oOcc Is Nothing Then
	MsgBox("You did not select anything. Exiting.", , "")
	Exit Sub
End If

Dim oDoc As Document 
oDoc = ThisApplication.Documents.Open(oOcc.Definition.Document.FullFileName)

' Convert it to a sheet metal type.
oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

Dim smDef As SheetMetalComponentDefinition
smDef = oDoc.ComponentDefinition

' Unfold the part.  This will activate the flat pattern environment.
smDef.Unfold

' Exit the flat pattern environment.
smDef.FlatPattern.ExitEdit

oDoc = ThisApplication.ActiveDocument
'Dim CadlineSheetMetal As SheetMetalComponentDefinition
CadlineSheetMetal = oDoc.ComponentDefinition
'CadlineSheetMetal.FlatPattern.Delete
CadlineSheetMetal.Unfold
Cadline = ThisApplication.ActiveDocument.ComponentDefinition
X = 10 * (Cadline.RangeBox.MaxPoint.X - Cadline.RangeBox.MinPoint.X)
Y = 10 * (Cadline.RangeBox.MaxPoint.Y - Cadline.RangeBox.MinPoint.Y)
Z = 10 * (Cadline.RangeBox.MaxPoint.Z - Cadline.RangeBox.MinPoint.Z)
Parameter.Quiet = True
THICKNESS = MinOfMany(X, Y, Z)

Try
ThisDoc.Document.ComponentDefinition.UseSheetMetalStyleThickness = False
Catch
	MsgBox("could not set 'UseSheetMetalStyleThickness'", , "iLogic")
	Exit Sub
End Try

Dim oSheetMetalCompDef As SheetMetalComponentDefinition
oSheetMetalCompDef = oDoc.ComponentDefinition

Dim oThicknessParam As Parameter
oThicknessParam = oSheetMetalCompDef.Thickness
oThicknessParam.Value = THICKNESS / 10
'oDoc.Update

LENGTH = MaxOfMany(X, Y, Z)
If X < LENGTH Then
	WIDTH = X
End If
If Y < LENGTH Then
	WIDTH = Y
End If
If Z < LENGTH Then
	WIDTH = Y
End If
iProperties.Value("Custom", "LENGTH") = Round(LENGTH, 1)
iProperties.Value("Custom", "WIDTH") = Round(WIDTH, 1)
iProperties.Value("Custom", "THICKNESS") = Round(THICKNESS, 1)

iProperties.Value("Project", "Authority") = iProperties.Value("Custom", "THICKNESS")
iProperties.Value("Summary", "Comments") = "laser"
RuleParametersOutput()
iLogicVb.UpdateWhenDone = True

CadlineSheetMetal = oDoc.ComponentDefinition
InventorVb.DocumentUpdate()

'set iproperty to use ISO view on save
oDoc.SetThumbnailSaveOption _
(ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)

'get current colorcheme name 
oColorScheme = ThisApplication.ActiveColorScheme.Name

'Change to Presentation
ThisApplication.ColorSchemes.Item("Presentation").Activate
ThisApplication.ColorSchemes.BackgroundType = 52737

'set iproperty to use ISO view on save
oDoc.SetThumbnailSaveOption _
(ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)


oDoc.Save
'Change back to original scheme
ThisApplication.ColorSchemes.Item(oColorScheme).Activate

Call oDoc.Close(True)

 

Message 6 of 10

Its working till here:

Try
ThisDoc.Document.ComponentDefinition.UseSheetMetalStyleThickness = False
Catch
	MsgBox("Could not set 'UseSheetMetalStyleThickness'", , "iLogic")
	Exit Sub
End Try

Then I get:

damjan_baraga_0-1716234350276.png

 

 

Message 7 of 10

My apologies, I put that error catch in, but I misinterpreted the error. It should be as shown below:

 

 

Try
	oDoc.ComponentDefinition.UseSheetMetalStyleThickness = False
Catch
	MsgBox("could not set 'UseSheetMetalStyleThickness'", , "iLogic")
	Exit Sub
End Try

 

Message 8 of 10

There must some errors, too, because I don't get data in iProperties.

damjan_baraga_0-1716238767937.png

 

Message 9 of 10

iProperties.Value(oOcc.Name, "Custom", "LENGTH") = Round(LENGTH, 2)
iProperties.Value(oOcc.Name, "Custom", "WIDTH") = Round(WIDTH, 2)
iProperties.Value(oOcc.Name, "Custom", "THICKNESS") = Round(THICKNESS, 2)

iProperties.Value(oOcc.Name, "Project", "Authority") = iProperties.Value("Custom", "THICKNESS")
iProperties.Value(oOcc.Name, "Summary", "Comments") = "laser"
Message 10 of 10

Now working. Many Thanks.

 

 

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

Post to forums  

Autodesk Design & Make Report