Automate view Labels

Automate view Labels

Joffie93
Contributor Contributor
578 Views
6 Replies
Message 1 of 7

Automate view Labels

Joffie93
Contributor
Contributor

I'm trying to automate view labels that will update as the item numbers in the parts list change with drawing revisions.  the format I'm trying to get is:

Item <item # from BOM>

<stock type>

<# required>  

I've been trying to modify this code to work. but i have to admit I'm not very good at Ilogic or coding 

Screenshot 2022-12-21 131844.jpg

 

0 Likes
Accepted solutions (1)
579 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

I think you will be better off reading the item number out of the partslist instead of the BOM. Is the partslist where you do the item setting? At least this way if you override the partslist in the drawing then your code can be ran to update the view label. If you do decide to go the partslist route here is a sample in VBA language for going through the partslist rows

Can you post the code you want to work with? A screenshot give you an idea of what your attempting but it is cleaner to have a physical copy of the code from which to test.  You can attach it through this format tool or straight from ilogic editor. 

AAcheson_0-1671652534249.png

 

 

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

Joffie93
Contributor
Contributor
this is the code I'm starting with realized that this is written to work with vault which my company doesn't use. so iv been playing with editing the code to work with out it with not a lot of progress.


If
ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then Dim oView As DrawingView oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View") MsgBox(oView.Name) oView.ShowLabel = True 'show label for selected view 'Inventor.Document.PropertySets.Item("Design Tracking Properties") 'ThisPartInfo = DrawingView.ScaleString & " SCALE" & vbLf & partName & " Name" & vbLf & DesProperty.Value & " Description" oPartNumber = "<Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number'> PART NUMBER </Property><Br/>" o_iPropID_1 = ThisDoc.ModelDocument.PropertySets.Item("User Defined Properties").Item("Member").PropId oMember = "<Property Document='model' PropertySet='User Defined Properties' " _ & "Property='My_iProp_1' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _ & o_iPropID_1 & "'>My_iProp_1</Property><Br/>" o_iPropID_2 = ThisDoc.ModelDocument.PropertySets.Item("User Defined Properties").Item("TotalQty").PropId oTotalQty = "<Property Document='model' PropertySet='User Defined Properties' " _ & "Property='My_iProp_2' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _ & o_iPropID_2 & "'>My_iProp_2</Property>" oView.Label.FormattedText = oPartNumber & oMember & oTotalQty & " X OFF " End If
0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

So this code is adding the custom iproperties from the assembly to the drawing view label. So this is working. If it isn't working for you this mean that the custom iproperties don't exist. These are manually added and not automatically retrieved from the BOM. Is this what you intended to do with the code? If your view contains a sub assembly within a  view rep you could retrieve the BOM information from the parent assembly. If your view is only a sub assembly with no link to the parent assembly you would need to drive the BOM information from the parent assembly to the sub assembly custom iproperties and out to the drawing. I personally think this information should only be written in the main general arrangement partslist so as to keep it out of assembly/part documents. You look at the main drawing and this will tell you how many of the sub assemblies to make. 

AAcheson_0-1671748713371.png

 

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

Joffie93
Contributor
Contributor

what I'm trying to do is create a label for views of parts placed as detail on a drawing of pressure vessels that will update as the parts list changes through revisions. only the first line of the label really needs to be automated but I need to use the item number from the parts list of the drawing to properly call out the part I'm detailing. an example of one of my drawings and some of the type of label I want to automat in the to left corner 

 

 

 

 

 

 

Screenshot 2022-12-23 075630.jpg 

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor
Accepted solution

I think this will be a better fit for what you need. It works with the View Document and Partslist Row Document  to bring back the Partslist Value for 'ITEM" and "ITEM QTY". Then Retrieves the View Document iproperty " stock type" and changes the view label. 

 

It is currently looping through all the views on the sheet. this will work assuming the criteria is correct and you don't mind overwriting view labels. The criteria may need to be changed or you can take out the view loop and use a pick function for each view. 

 

 

 If Not ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then MessageBox.Show("Not a drawing! Exiting") : Return
	  
	  Dim DrawDoc As DrawingDocument = ThisDoc.Document
	  Dim ActiveSheet As Sheet = DrawDoc.ActiveSheet

	  'Dim View As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view")
	  
	  For Each View In ActiveSheet.DrawingViews
	 
	       Dim ViewDoc As Document = View.ReferencedDocumentDescriptor.ReferencedDocument
		  
		   If View.Parent.PartsLists.Count = 0 Then MessageBox.Show("No Partlist Exiting") : Return
		   
		   	Dim PartsList As PartsList = View.Parent.PartsLists.Item(1)

			For Each Row As PartsListRow In PartsList.PartsListRows
				
				Dim DBomRow As DrawingBOMRow = Row.ReferencedRows.Item(1)
				Dim RowDoc As Document = DBomRow.BOMRow.ComponentDefinitions.Item(1).Document
				
				If ViewDoc Is RowDoc Then
					Try
				       Dim ItemCell As PartsListCell = Row.Item("ITEM")
					   Dim QtyCell As PartsListCell = Row.Item("ITEM QTY")
					   
					   Dim Item As String = ItemCell.Value
					   Dim Qty As String = QtyCell.Value
					 
					   Dim stocktype As String = ViewDoc.PropertySets.Item("User Defined Properties").Item("stock type").Value
					   
						View.ShowLabel = True 'show label for selected view
						View.Label.FormattedText = "ITEM " & Item & vbLf & stocktype & vbLf & Qty & " X OFF "
					Catch 
						MessageBox.Show("Error in Setting View Label of View: " & View.Name & vbLf & "Check if the iproperty / Partslist Value exists" , "Error Message")
					End Try
				End If
				
			Next
	Next

 

 

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

Joffie93
Contributor
Contributor

This works perfect thank you 

0 Likes