Adding Partslist to all Sheets Based on Title Block of Sheet

Adding Partslist to all Sheets Based on Title Block of Sheet

jamesrHA2LQ
Explorer Explorer
237 Views
2 Replies
Message 1 of 3

Adding Partslist to all Sheets Based on Title Block of Sheet

jamesrHA2LQ
Explorer
Explorer

I'm trying add a parts list to every sheet only if the sheet is using a specific Title Block.  I think my variable needs to be a String, so that I test the names of the Title Block.  I can assign a string variable to ActiveSheet.TitleBlock but then the variable doesn't iterate and stays constant.  If make the variable an object, and assign it oSheet.TitleBlock, then I'm not sure how to use the "if" statement to test for the correct title block.  Assigning an string to oSheet.TitleBlock just gives me the "Unable to cast COM object to class type String" error.

 

 

Any help would be awesome,

 

thanks.

 

'Places Parts List at top right corner for all drawing sheets with Anton B Title Block

Sub Main()
	
	Dim oDrawDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDrawDoc.ActiveSheet
	Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
	Dim oBorder As Border = oSheet.Border
	Dim oPlacementPoint As Point2d
	Dim sTitleBlock As String
	
	For Each oSheet In oDrawDoc.Sheets
	oSheet.Update
	oDrawDoc.Update
		
		sTitleBlock = oSheet.TitleBlock

		If sTitleBlock = "Anton B"
			
			oPlacementPoint = oBorder.RangeBox.MaxPoint
			Dim oPartsList As PartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
			
		End If	
		
	Next

End Sub

 

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

JelteDeJong
Mentor
Mentor

try it like this:

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

For Each oSheet As Sheet In oDrawDoc.Sheets
	Dim sTitleBlock As String = oSheet.TitleBlock.Name

	If (sTitleBlock.Equals("Anton B", StringComparison.InvariantCultureIgnoreCase)) Then
		Dim oDrawingView As DrawingView = oSheet.DrawingViews.Item(1)
		Dim oBorder As Border = oSheet.Border

		Dim oPlacementPoint As Point2d = oBorder.RangeBox.MaxPoint
		oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

	End If
Next

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

jamesrHA2LQ
Explorer
Explorer

Thanks!  I actually ended up making the variable an object and using:

 

If oTitleBlock.Name = "Anton B" 

 And that worked great.

 

Thanks again.

0 Likes