Having trouble with a parts list rule.

Having trouble with a parts list rule.

Brian.Price
Advocate Advocate
498 Views
2 Replies
Message 1 of 3

Having trouble with a parts list rule.

Brian.Price
Advocate
Advocate

I have an ilogic rule that I run to remove, add, and sort my parts lists. But for some reason it doesn't always work.

I made a template using a frame generated assembly with a general drawing. I then ilogic copied the drawing and model to new folders for the different sizes that I am going to make. I then open each model and drawing and edit them to the correct dimensions then I complete the drawing. But every once in a while the parts list rule shows and error and won't run. I can seem to figure out why. Any help on this is greatly appreciated, thanks in advance.

 

Here is the rule:

 

Sub Main
	Partslist
	Renumber
	PLSTYLE
End Sub

Sub Partslist
'Create or replace Partslist
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
    
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
		
Try 
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try

If partslistpresent=True
        
        Dim oPartsList As PartsList
        oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
        oPartsList.Delete
        
End If
                
    Dim oDrawingView As DrawingView
    oDrawingView = oSheet.DrawingViews(1)
    
    Dim oBorder As Border
    oBorder = oSheet.Border
            
		xMax = oBorder.RangeBox.MaxPoint.X - 0
		yMax = oBorder.RangeBox.MaxPoint.Y
		xMin = oBorder.RangeBox.MinPoint.X 
		yMin = oBorder.RangeBox.MinPoint.Y
	

Dim oPlacementPoint1 As Point2d
    	oPlacementPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(xMax, yMax)	
    Dim oPartsList1 As PartsList
		oSheet.PartsLists.Add(oDrawingView, oPlacementPoint1)
		oPartsList1 = oDrawingDoc.ActiveSheet.PartsLists.Item(1)	
		
		PLxrev = (oPartsList1.RangeBox.MaxPoint.X -oPartsList1.RangeBox.MinPoint.X)
		PLyrev = (oPartsList1.RangeBox.MaxPoint.Y -oPartsList1.RangeBox.MinPoint.Y)
		
		oPlaceX = xMax
		PL_Style = Parameter("PL_Style")
		If PL_Style = "ICM Parts List - Lower Right" Then
			oPlaceY = yMin + PLyrev + 2.8575
			End If
		If PL_Style = "ICM Parts List - Upper Right" Then
			oPlaceY = yMax
		End If

oPlacementPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX, oPlaceY)
	
oPartsList1.Position = oPlacementPoint2
oPartsList1.Sort("DWG# /TAG#")
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM
oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item(PL_Style)


Dim oPartList As PartsList
oPartList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
Dim i As Long
For i = 1 To oPartList.PartsListRows.Count
oCell = oPartList.PartsListRows.Item(i).Item("CUT LENGTH")
oCell2 = oPartList.PartsListRows.Item(i).Item("CUT_LTH")
If oCell2.Value = "" Then
oCell.Value = ""
End If
Next
End Sub

Sub Renumber
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oPartList As Partslist
oPartList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
Dim i As Long
For i = 1 To oPartList.PartsListRows.Count
oCell = oPartList.PartsListRows.Item(i).Item("CUT LENGTH")
oCell2 = oPartList.PartsListRows.Item(i).Item("CUT_LTH")
If oCell2.Value = "" Then
oCell.Value = ""
End If
Next

'oPartList.Sort("ITEM", True)
oPartList.Sort2("ITEM",True,"ITEM",True,"ITEM",True,True, True)
oPartList.Renumber
oPartList.SaveItemOverridesToBOM


End Sub

Sub PLSTYLE
Dim openDoc As Document
   'assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
        
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet

    'Look for partlist within drawing. End rule, if it doesn't exist.
    'say there is a Partslist on the sheet.
    Dim oPartslist As Partslist
    oPartslist = oSheet.PartsLists(1)

    'set parts list to a specific style
	If PL_Style= "ICM Parts List - Upper Right" Then
	oPartslist.Style = oDrawDoc.StylesManager.PartsListStyles.Item("ICM Parts List - Upper Right")
   End If
	If PL_Style= "ICM Parts List - Lower Right" Then
	oPartslist.Style = oDrawDoc.StylesManager.PartsListStyles.Item("ICM Parts List - Lower Right")
End If 	
End Sub

 

 

1.PNG2.PNG 

0 Likes
499 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

On the screenshot, I see that the function call "oSheet.PartsLists.Add(oDrawingView, oPlacementPoint1)" in the sub "Partslist()" is getting an invalid argument. That means that the view or the insert point is not valid. I changed your code a bit and added a message box just before the parts list gets added. The message box should tell you the name of the view that is used and the target position. You can try this code when your rule is not working. maybe you will get some more useful information.

 

Sub Partslist()
    'Create or replace Partslist
    Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim oSheet As Sheet = oDrawingDoc.ActiveSheet

    If (oSheet.PartsLists.Count > 0) Then
        Dim oPartsList As PartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
        oPartsList.Delete()
    End If

    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    Dim oBorder As Border = oSheet.Border

    Dim xMax = oBorder.RangeBox.MaxPoint.X
    Dim yMax = oBorder.RangeBox.MaxPoint.Y
    Dim xMin = oBorder.RangeBox.MinPoint.X
    Dim yMin = oBorder.RangeBox.MinPoint.Y


    Dim oPlacementPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(xMax, yMax)

    MsgBox(oDrawingView.Name & ": " & oPlacementPoint1.X & "," & oPlacementPoint1.Y)

    Dim oPartsList1 As PartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint1)

    oPartsList1 = oDrawingDoc.ActiveSheet.PartsLists.Item(1)

    Dim PLxrev = (oPartsList1.RangeBox.MaxPoint.X - oPartsList1.RangeBox.MinPoint.X)
    Dim PLyrev = (oPartsList1.RangeBox.MaxPoint.Y - oPartsList1.RangeBox.MinPoint.Y)

    Dim oPlaceX = xMax
    Dim oPlaceY = 0
    Dim PL_Style = Parameter("PL_Style")
    If PL_Style = "ICM Parts List - Lower Right" Then
        oPlaceY = yMin + PLyrev + 2.8575
    ElseIf PL_Style = "ICM Parts List - Upper Right" Then
        oPlaceY = yMax
    End If

    Dim oPlacementPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX, oPlaceY)

    oPartsList1.Position = oPlacementPoint2
    oPartsList1.Sort("DWG# /TAG#")
    oPartsList1.Renumber()
    oPartsList1.SaveItemOverridesToBOM()
    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item(PL_Style)


    Dim oPartList As PartsList
    oPartList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
    Dim i As Long
    For i = 1 To oPartList.PartsListRows.Count
        Dim oCell = oPartList.PartsListRows.Item(i).Item("CUT LENGTH")
        Dim oCell2 = oPartList.PartsListRows.Item(i).Item("CUT_LTH")
        If oCell2.Value = "" Then
            oCell.Value = ""
        End If
    Next
End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

Brian.Price
Advocate
Advocate

Thanks for the tips. I used your code but for some reason it puts the parts list in a different location. The coordinates seem to be the same, not sure why it does that. Anyways I ran into the same issue while using your code too. 

I later found out that when this happens if I add a balloon it prompts to add a parts list and then the code works again.

Which is weird because I often use this on a fresh drawing that has no parts list and it adds it.

 

Perhaps there's an issue when it looks for the parts list and finds nothing after a parts list has been removed?

0 Likes