Placing parts list in drawing with ILogic

Placing parts list in drawing with ILogic

Thomas.Long
Advocate Advocate
571 Views
1 Reply
Message 1 of 2

Placing parts list in drawing with ILogic

Thomas.Long
Advocate
Advocate

 

I have an ilogic program that creates a drawing for an assembly. 90% of the time this runs without error. However if the program is run multiple times (say if something happened where I want to recreate the drawing) it gives the following error when I comment out the on error resume next in the function for placing the parts list:

 

(Exception from HRESULT: 0x80070057 (E_INVALIDARG))

That error occurs on the point where the  parts list is actually added. With the on error resume next, it simply ignores adding the parts list, completes the function without it and creates the rest of the drawing. It will give this error every time on this assembly until a completely new file is done from scratch. 

Why is it doing that? Does anyone know how to fix it?

 

 

'Places a structured view of the parts list and shifts it to the specified location
'Possible positions are 'Top Right', 'Top Left', 'Bottom Right', 'Bottom Left'
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Function PlacePartsList(oDrawingDoc As DrawingDocument, Position As String)

	On Error Resume Next

'Declare Document Variables
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oSheet As Sheet
	Dim oDrawingView As DrawingView
	Dim oPlacementPoint As Point2d
	Dim oPartsList As PartsList 
	Dim oBorder As Border
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


'Declare Local Variables
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	Dim oStyle As String
	Dim oPlaceX As Double
	Dim oPlaceY As Double
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

	
'Initialize variables
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oSheet = oDrawingDoc.ActiveSheet
	oDrawingView = oSheet.DrawingViews(1)
	oBorder = oSheet.Border
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	

'create parts list
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oBorder.RangeBox.MinPoint, PartsListLevelEnum.kStructured)
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	

'Set position
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	If Position = "Top Right"
		oPlaceX = oBorder.RangeBox.MaxPoint.X
		oPlaceY = oBorder.RangeBox.MaxPoint.Y
	Else If Position = "Top Left"
		oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
		oPlaceY = oBorder.RangeBox.MaxPoint.Y
	Else If Position = "Bottom Right"
		oPlaceX = oBorder.RangeBox.MinPoint.X 
		oPlaceY = oBorder.RangeBox.MinPoint.Y + (oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y)
	Else If Position = "Bottom Left"
		oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
		oPlaceY = oBorder.RangeBox.MinPoint.Y + (oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y)
	Else
		MsgBox("Incorrect position statement. Please correct input position and input")
		Exit Function
	End If
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	

'Move parts list
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX,oPlaceY)
	oPartslist.position = oPlacementPoint
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

End Function
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\  

 

0 Likes
572 Views
1 Reply
Reply (1)
Message 2 of 2

Owner2229
Advisor
Advisor

I'm gonna have nightmares from all the back slashes...

Anyway, try it now. I've added some proper error and exception handling and moved the PartsList creation after the input verification.

 

'Places a structured view of the parts list and shifts it to the specified location
'Possible positions are 'Top Right', 'Top Left', 'Bottom Right', 'Bottom Left'
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub PlacePartsList(oDrawingDoc As DrawingDocument, Position As String)
	Try
		Dim oSheet As Sheet = oDrawingDoc.ActiveSheet
		If oSheet.DrawingViews.Count = 0 Then Exit Sub
		Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
		Dim oBorder As Border = oSheet.Border
		Dim oPlaceX As Double
		Dim oPlaceY As Double
		
		If Position = "Top Right"
			oPlaceX = oBorder.RangeBox.MaxPoint.X
			oPlaceY = oBorder.RangeBox.MaxPoint.Y
		ElseIf Position = "Top Left"
			oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
			oPlaceY = oBorder.RangeBox.MaxPoint.Y
		ElseIf Position = "Bottom Right"
			oPlaceX = oBorder.RangeBox.MinPoint.X 
			oPlaceY = oBorder.RangeBox.MinPoint.Y + (oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y)
		ElseIf Position = "Bottom Left"
			oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
			oPlaceY = oBorder.RangeBox.MinPoint.Y + (oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y)
		Else
			MsgBox("Incorrect position statement. Please correct input position and input")
			Exit Sub
		End If
		
		Dim oPlacementPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX, oPlaceY)
		Dim oPartsList As PartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, PartsListLevelEnum.kStructured)
	Catch ex As Exception
		MsgBox(ex.Message)
	End Try
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes