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: 

Combining Rules

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
kwarrenH4ZT3
594 Views, 7 Replies

Combining Rules

kwarrenH4ZT3
Advocate
Advocate

I'm working on some iLogic to copy a view from one drawing to a new drawing then place a parts list from that view. Once the parts list is place to copy it back to the source drawing. Currently I have 3 different iLogic codes.

  1. One code that can copy the view to a new sheet from a template.
  2. One code that can place a parts list that is then sorted.
  3. One code that can copy the parts list to another drawing.

So I'm looking for some help on how to combine these. I would like to have the last code call back the source drawing to copy the parts list to but I'm having some difficulty figuring that out. I'm not sure if I need to do subs or move this to VBA. Any help would be appreciated.

 

''Copy View to new drawing
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument

oBaseSheet = oSrcDwg.Sheets(1)

Dim oDestDwg As DrawingDocument
''File Location to be Decided
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")

Dim oView As DrawingView
'Check to see if drawing is on the cover page.
Try
	oView = oBaseSheet.DrawingViews(1)
Catch
	MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
	MsgBox("No views found in the source drawing!")
	Return
End If


oModelDoc = oBaseSheet.DrawingViews(1)

Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
	oSheet.Activate
	Call oView.CopyTo(oSheet)
	Exit For
Next

'Used to save destination file
'Call oDestDwg.Save
'Used to close destination file
'Call oDestDwg.Close(True)

 

''Places Parts in drawing from view placed
Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDestDwg.Sheets(1)

Dim oBOM As BOM
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList

'Try to get the first view on the sheet
Try
	oView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("There is no view on the cover page","Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

'get the model that the view is looking at
oModelDoc =ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure  the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists

'clean up existing parts lists
For Each oPartsList In oPartsLists
	oPartsList.Delete
Next

'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
''Location of bom on border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d (oBorder.RangeBox.MaxPoint.X-20, oBorder.RangeBox.MaxPoint.Y-.95)

'Create new partsList
oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
'Changes parts list to new style.
oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")


''Sort Parts List
Dim oPartsList1 As PartsList
oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort2("VENDOR",1,"STOCK NUMBER",1,"SIZE",1,AutoSortOnUpdate,True)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM

 

'PartsList copy to destination folder

Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument

oBaseSheet = oSrcDwg.Sheets(1)

Dim oDestDwg As DrawingDocument
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")


Dim oPartsList As PartsList

'Checks to see if there is a parts list.
Try
	oPartsList = oBaseSheet.PartsLists.Item(1)
Catch
	MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

oModelDoc = oBaseSheet.PartsLists.Item(1)

'Moves parts list to oDestDwg
Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
    oSheet.Activate
    Call oPartsList.CopyTo(oSheet)
    Exit For
Next

 

0 Likes

Combining Rules

I'm working on some iLogic to copy a view from one drawing to a new drawing then place a parts list from that view. Once the parts list is place to copy it back to the source drawing. Currently I have 3 different iLogic codes.

  1. One code that can copy the view to a new sheet from a template.
  2. One code that can place a parts list that is then sorted.
  3. One code that can copy the parts list to another drawing.

So I'm looking for some help on how to combine these. I would like to have the last code call back the source drawing to copy the parts list to but I'm having some difficulty figuring that out. I'm not sure if I need to do subs or move this to VBA. Any help would be appreciated.

 

''Copy View to new drawing
Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument

oBaseSheet = oSrcDwg.Sheets(1)

Dim oDestDwg As DrawingDocument
''File Location to be Decided
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")

Dim oView As DrawingView
'Check to see if drawing is on the cover page.
Try
	oView = oBaseSheet.DrawingViews(1)
Catch
	MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
	MsgBox("No views found in the source drawing!")
	Return
End If


oModelDoc = oBaseSheet.DrawingViews(1)

Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
	oSheet.Activate
	Call oView.CopyTo(oSheet)
	Exit For
Next

'Used to save destination file
'Call oDestDwg.Save
'Used to close destination file
'Call oDestDwg.Close(True)

 

''Places Parts in drawing from view placed
Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDestDwg.Sheets(1)

Dim oBOM As BOM
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList

'Try to get the first view on the sheet
Try
	oView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("There is no view on the cover page","Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

'get the model that the view is looking at
oModelDoc =ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure  the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists

'clean up existing parts lists
For Each oPartsList In oPartsLists
	oPartsList.Delete
Next

'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
''Location of bom on border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d (oBorder.RangeBox.MaxPoint.X-20, oBorder.RangeBox.MaxPoint.Y-.95)

'Create new partsList
oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
'Changes parts list to new style.
oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")


''Sort Parts List
Dim oPartsList1 As PartsList
oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort2("VENDOR",1,"STOCK NUMBER",1,"SIZE",1,AutoSortOnUpdate,True)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM

 

'PartsList copy to destination folder

Dim oSrcDwg As DrawingDocument
oSrcDwg = ThisApplication.ActiveDocument

oBaseSheet = oSrcDwg.Sheets(1)

Dim oDestDwg As DrawingDocument
oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")


Dim oPartsList As PartsList

'Checks to see if there is a parts list.
Try
	oPartsList = oBaseSheet.PartsLists.Item(1)
Catch
	MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

oModelDoc = oBaseSheet.PartsLists.Item(1)

'Moves parts list to oDestDwg
Dim oSheet As Sheet
For Each oSheet In oDestDwg.Sheets
    oSheet.Activate
    Call oPartsList.CopyTo(oSheet)
    Exit For
Next

 

Labels (2)
7 REPLIES 7
Message 2 of 8
A.Acheson
in reply to: kwarrenH4ZT3

A.Acheson
Mentor
Mentor

The first question would be do you want to keep this all as separate rules or to create one rule with individual subs? Just looking at what you have it is only a matter of passing each drawing document in as a variable and launch the next sub routine at the end of each or combine them where possible the operations happening on the same document. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

The first question would be do you want to keep this all as separate rules or to create one rule with individual subs? Just looking at what you have it is only a matter of passing each drawing document in as a variable and launch the next sub routine at the end of each or combine them where possible the operations happening on the same document. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8
kwarrenH4ZT3
in reply to: A.Acheson

kwarrenH4ZT3
Advocate
Advocate

I would like to have them in the same rule. Each rule would have to run once the rule before it finishes.

0 Likes

I would like to have them in the same rule. Each rule would have to run once the rule before it finishes.

Message 4 of 8
Cadkunde.nl
in reply to: kwarrenH4ZT3

Cadkunde.nl
Collaborator
Collaborator
Accepted solution

I think you want something like this:

 

Class iRule
	Public test As String = "This variable works in every sub"
	Sub Main()
		Rule1()
		Rule2()
		Rule3()
	End Sub
	
	Sub Rule1()
		'Copy paste content of your first rule here
	End Sub
	
	Sub Rule2()
		'Copy paste content of your second rule here
	End Sub
	
	Sub Rule3()
		'Copy paste content of your third rule here
	End Sub
End Class

I think you want something like this:

 

Class iRule
	Public test As String = "This variable works in every sub"
	Sub Main()
		Rule1()
		Rule2()
		Rule3()
	End Sub
	
	Sub Rule1()
		'Copy paste content of your first rule here
	End Sub
	
	Sub Rule2()
		'Copy paste content of your second rule here
	End Sub
	
	Sub Rule3()
		'Copy paste content of your third rule here
	End Sub
End Class
Message 5 of 8
tyler.warner
in reply to: kwarrenH4ZT3

tyler.warner
Advocate
Advocate

This AU Course can help understand some of the differences between functions, subs, classes. See Tips #4-6. There is a video to go along with the documentation.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.

This AU Course can help understand some of the differences between functions, subs, classes. See Tips #4-6. There is a video to go along with the documentation.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
Message 6 of 8
kwarrenH4ZT3
in reply to: kwarrenH4ZT3

kwarrenH4ZT3
Advocate
Advocate

Thank you @Cadkunde.nl and @tyler.warner this is getting me in the right directions. Right now I just trying to get the first 2 rules to work together and keep getting an error on line 65 that no view with the name "View9" was found but there is a view shown on the new sheet. I feel like I'm missing something.

 

Class iRule
	'Public test As String = "This variable works in every sub"
	Public oSrcDWG As DrawingDocument
	Public oDestDwg As DrawingDocument
	Public oView As DrawingView
	Public oSheet As Sheet


	Sub Main()
		oSrcDWG = ThisApplication.ActiveDocument


		''File Location to be Decided
		oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")

		Rule1()

		Rule2()
		'Rule3()
	End Sub

	Sub Rule1()
		''Copy View to new drawing
		oBaseSheet = oSrcDWG.Sheets(1)
		'Check to see if drawing is on the cover page.
		Try
			oView = oBaseSheet.DrawingViews(1)
		Catch
			MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Return
		End Try

		If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
			MsgBox("No views found in the source drawing!")
			Return
		End If
		oModelDoc = oBaseSheet.DrawingViews(1)
		'Dim oSheet As Sheet
		For Each oSheet In oDestDwg.Sheets
			oSheet.Activate
			Call oView.CopyTo(oSheet)
			Exit For
		Next
	End Sub

	Sub Rule2()
		''Places Parts in drawing from view placed
		'Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
		oSheet = oDestDwg.Sheets(1)

		Dim oBOM As BOM
		'Dim oView As DrawingView
		Dim oPartsLists As PartsLists
		Dim oPartsList As PartsList

		'Try to get the first view on the sheet
		Try
			oView = oSheet.DrawingViews(1)
		Catch
			MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Return
		End Try

		'get the model that the view is looking at
		oModelDoc = ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument

		'get the BOM database
		oBOM = oModelDoc.ComponentDefinition.BOM
		' Make sure  the BOM view is enabled
		oBOM.PartsOnlyViewEnabled = True
		'get the PartsLists collection
		oPartsLists = oSheet.PartsLists

		'clean up existing parts lists
		For Each oPartsList In oPartsLists
			oPartsList.Delete
		Next

		'Setting BOM position
		Dim BomPlacementPoint As Point2d
		Dim oBorder As Border = oSheet.Border
		''Location of bom on border
		BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MaxPoint.X - 20, oBorder.RangeBox.MaxPoint.Y - .95)

		'Create new partsList
		oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
		'Changes parts list to new style.
		oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")

		''Sort Parts List
		Dim oPartsList1 As PartsList
		oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
		oPartsList1.Sort2("VENDOR", 1, "STOCK NUMBER", 1, "SIZE", 1, AutoSortOnUpdate, True)
		oPartsList1.Renumber
		oPartsList1.SaveItemOverridesToBOM
	End Sub

	'	Sub Rule3()
	'		'PartsList copy to destination folder

	'		Dim oSrcDwg As DrawingDocument
	'		oSrcDwg = ThisApplication.ActiveDocument

	'		oBaseSheet = oSrcDwg.Sheets(1)

	'		Dim oDestDwg As DrawingDocument
	'		oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")


	'		Dim oPartsList As PartsList

	'		'Checks to see if there is a parts list.
	'		Try
	'			oPartsList = oBaseSheet.PartsLists.Item(1)
	'		Catch
	'			MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
	'			Return
	'		End Try

	'		oModelDoc = oBaseSheet.PartsLists.Item(1)

	'		'Moves parts list to oDestDwg
	'		Dim oSheet As Sheet
	'		For Each oSheet In oDestDwg.Sheets
	'			oSheet.Activate
	'			Call oPartsList.CopyTo(oSheet)
	'			Exit For
	'		Next
	'	End Sub

End Class

 

0 Likes

Thank you @Cadkunde.nl and @tyler.warner this is getting me in the right directions. Right now I just trying to get the first 2 rules to work together and keep getting an error on line 65 that no view with the name "View9" was found but there is a view shown on the new sheet. I feel like I'm missing something.

 

Class iRule
	'Public test As String = "This variable works in every sub"
	Public oSrcDWG As DrawingDocument
	Public oDestDwg As DrawingDocument
	Public oView As DrawingView
	Public oSheet As Sheet


	Sub Main()
		oSrcDWG = ThisApplication.ActiveDocument


		''File Location to be Decided
		oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")

		Rule1()

		Rule2()
		'Rule3()
	End Sub

	Sub Rule1()
		''Copy View to new drawing
		oBaseSheet = oSrcDWG.Sheets(1)
		'Check to see if drawing is on the cover page.
		Try
			oView = oBaseSheet.DrawingViews(1)
		Catch
			MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Return
		End Try

		If oSrcDwg.ActiveSheet.DrawingViews.Count < 1 Then
			MsgBox("No views found in the source drawing!")
			Return
		End If
		oModelDoc = oBaseSheet.DrawingViews(1)
		'Dim oSheet As Sheet
		For Each oSheet In oDestDwg.Sheets
			oSheet.Activate
			Call oView.CopyTo(oSheet)
			Exit For
		Next
	End Sub

	Sub Rule2()
		''Places Parts in drawing from view placed
		'Dim oDestDwg As DrawingDocument = ThisApplication.ActiveDocument
		oSheet = oDestDwg.Sheets(1)

		Dim oBOM As BOM
		'Dim oView As DrawingView
		Dim oPartsLists As PartsLists
		Dim oPartsList As PartsList

		'Try to get the first view on the sheet
		Try
			oView = oSheet.DrawingViews(1)
		Catch
			MessageBox.Show("There is no view on the cover page", "Place a view", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Return
		End Try

		'get the model that the view is looking at
		oModelDoc = ThisDrawing.Sheet(“COVER:1”).View(oView.Name).ModelDocument

		'get the BOM database
		oBOM = oModelDoc.ComponentDefinition.BOM
		' Make sure  the BOM view is enabled
		oBOM.PartsOnlyViewEnabled = True
		'get the PartsLists collection
		oPartsLists = oSheet.PartsLists

		'clean up existing parts lists
		For Each oPartsList In oPartsLists
			oPartsList.Delete
		Next

		'Setting BOM position
		Dim BomPlacementPoint As Point2d
		Dim oBorder As Border = oSheet.Border
		''Location of bom on border
		BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MaxPoint.X - 20, oBorder.RangeBox.MaxPoint.Y - .95)

		'Create new partsList
		oPartsList = oPartsLists.Add(oView, BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
		'Changes parts list to new style.
		oPartsList.Style = oDestDwg.StylesManager.PartsListStyles.Item("BOM (Purchasing)")

		''Sort Parts List
		Dim oPartsList1 As PartsList
		oPartsList1 = oDestDwg.ActiveSheet.PartsLists.Item(1)
		oPartsList1.Sort2("VENDOR", 1, "STOCK NUMBER", 1, "SIZE", 1, AutoSortOnUpdate, True)
		oPartsList1.Renumber
		oPartsList1.SaveItemOverridesToBOM
	End Sub

	'	Sub Rule3()
	'		'PartsList copy to destination folder

	'		Dim oSrcDwg As DrawingDocument
	'		oSrcDwg = ThisApplication.ActiveDocument

	'		oBaseSheet = oSrcDwg.Sheets(1)

	'		Dim oDestDwg As DrawingDocument
	'		oDestDwg = ThisApplication.Documents.Open("C:\CA Workspace\CAD Standards\Templates\English\BOM DRAWING.idw")


	'		Dim oPartsList As PartsList

	'		'Checks to see if there is a parts list.
	'		Try
	'			oPartsList = oBaseSheet.PartsLists.Item(1)
	'		Catch
	'			MessageBox.Show("There is no parts list on the cover page", "Place a parts list", MessageBoxButtons.OK, MessageBoxIcon.Error)
	'			Return
	'		End Try

	'		oModelDoc = oBaseSheet.PartsLists.Item(1)

	'		'Moves parts list to oDestDwg
	'		Dim oSheet As Sheet
	'		For Each oSheet In oDestDwg.Sheets
	'			oSheet.Activate
	'			Call oPartsList.CopyTo(oSheet)
	'			Exit For
	'		Next
	'	End Sub

End Class

 

Message 7 of 8
A.Acheson
in reply to: kwarrenH4ZT3

A.Acheson
Mentor
Mentor
Accepted solution

You will need to  remove the reference to ilogic model Document. If you look at object reference of this it will be for the the document you originally launched the rule from and not the document your currently in which should be the temporary drawing.  Use the API method instead. You may have to "activate" the drawing document/ sheet as well. 

Dim assyDocName As String =  oView.ReferencedDocumentDescriptor.FullDocumentName

'open assembly doc invisibly  
Dim oModelDoc As AssemblyDocument = ThisApplication.Documents.Open(assyDocName, False

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

You will need to  remove the reference to ilogic model Document. If you look at object reference of this it will be for the the document you originally launched the rule from and not the document your currently in which should be the temporary drawing.  Use the API method instead. You may have to "activate" the drawing document/ sheet as well. 

Dim assyDocName As String =  oView.ReferencedDocumentDescriptor.FullDocumentName

'open assembly doc invisibly  
Dim oModelDoc As AssemblyDocument = ThisApplication.Documents.Open(assyDocName, False

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 8
kwarrenH4ZT3
in reply to: kwarrenH4ZT3

kwarrenH4ZT3
Advocate
Advocate

@A.Acheson That did the trick. It is now working correctly just need to add a few checks so no one runs it if there already is a parts only parts list. Thank you for the help!

@A.Acheson That did the trick. It is now working correctly just need to add a few checks so no one runs it if there already is a parts only parts list. Thank you for the help!

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

Post to forums  

Autodesk Design & Make Report