ilogic: item number from part list into drawing view label name

ilogic: item number from part list into drawing view label name

Anonymous
Not applicable
3,093 Views
14 Replies
Message 1 of 15

ilogic: item number from part list into drawing view label name

Anonymous
Not applicable

Hi All, 

I was browsing the entire forum and I found ilogic code, but it´s probably for old version. 

I use Inventor 2020. 

I have many drawing views in sheet. So I want iLogic code for automatic nameing the labels. Is possible to edit following code? 

 


' Set a reference to the drawing document.' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oSheets As Sheets Dim Sheet As Inventor.Sheet Dim oViews As DrawingViews Dim oView As DrawingView For Each oSheet In oDrawDoc.Sheets 'For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews If oView.ViewType <> 10504 Then ' Not kProjectedDrawingViewType 'Get the full filename Of the view model Dim oModelFileName As String oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName 'MessageBox.Show("view model name" & oModelFileName, "Title") Dim oPartList As PartsList 'try and get the parts list form the table of this sheet Try oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1) Catch 'on error try and search all sheets for first found parts list 'iterate trough each sheet Dim i As Long For i = 1 To oDrawDoc.Sheets.Count If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For Next oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1) 'MessageBox.Show("parts list found on: " & i, "Title") End Try ' Iterate through the contents of the parts list. Dim j As Long For j = 1 To oPartList.PartsListRows.Count ' Get the current row. Dim oRow As PartsListRow oRow = oPartList.PartsListRows.Item(j) 'get filename of model in row Dim oRowFileName As String oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName 'compare the filenames 'Performs a text comparison, based on a case-insensitive text sort order 'If strings equal returns 0 If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then 'Get the value of Item from the Parts List 'Row name needs to be case sensitive or use 1 for first 2 for second etc. oCell = oPartList.PartsListRows.Item(j).Item("Item") 'Row name needs to be case sensitive or use 1 for first 2 for second etc. 'get the value of text in cell Dim oItemValue As String oItemValue = oCell.Value 'Show the view label oView.ShowLabel = True 'format the text first line oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>" 'format the text second line oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>" 'add to the view label oView.Label.FormattedText = oStringItem & oStringScale End If Next End If Next Next

Thank you very much. 

0 Likes
Accepted solutions (1)
3,094 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

Sorry, I didn´t attach the error message. 

 
0 Likes
Message 3 of 15

Anonymous
Not applicable

There is an Inventor Customization forum, maybe you will get more help there:

https://forums.autodesk.com/t5/inventor-customization/bd-p/120

0 Likes
Message 4 of 15

mcgyvr
Consultant
Consultant

The code you provided works just fine in 2020..

Something about your specific file is causing the code to fail..

You will need to try to troubleshoot what specific portion of the code is failing or provide your files so others can go through it



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 5 of 15

Anonymous
Not applicable

I tried the code in many drawings, nowhere successfully.

The .idw is attached. 

 

Thanks for help. 

 

0 Likes
Message 6 of 15

mcgyvr
Consultant
Consultant

@Anonymous wrote:

I tried the code in many drawings, nowhere successfully.

The .idw is attached. 

 

Thanks for help. 

 


I've run it on multiple drawings.. All successful.. 

 

Can you please provide a small dataset (idw, iam and ipt files zipped up) that doesn't work..

Just sharing/opening the idw generates errors on this side due to missing references,etc..

 

You also need a parts list placed on the drawing for the code to reference. I don't see one in that idw.



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 7 of 15

Anonymous
Not applicable

I don´t know whats wrong. 

The code done just one view, and then error pops up.

 

0 Likes
Message 8 of 15

mcgyvr
Consultant
Consultant

@Anonymous 

Where is the iam file?

I'm getting cyclical errors with your files. I'm not even sure what you are trying to do..

 

I'm not sure how you think that code is supposed to work but please do the following..

 

Create a new drawing..

Place a base view of an iam on it..

Then create a parts list..

Then place views of ipt files used in that iam file onto the page..

Then run the code..

It will update the view label to include the item number from the parts list of the iam file.

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 9 of 15

Anonymous
Not applicable

Hi, 

Sorry  about .aim, i tried by your procedure, but still error pops up. 

I hope, I add all ipt, aim, idw. 

 

Thnaks a lot.

0 Likes
Message 10 of 15

mcgyvr
Consultant
Consultant

@Anonymous wrote:

Hi, 

Sorry  about .aim, i tried by your procedure, but still error pops up. 

I hope, I add all ipt, aim, idw. 

 

Thnaks a lot.


Worked just fine here..

I opened your idw.. Ran the view ilogic rule and the ipt files got their detail label turned on and updated as shown here..

items.PNG



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 11 of 15

Anonymous
Not applicable

so, I don´t whats wrong with my Inventor... 

Is possible that I have some wrong setting? 

 

0 Likes
Message 12 of 15

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous ,,

 

I did a quick test on your files and saw it work as expected the same as @mcgyvr . Below is a version of your rule that I did a quick run through... I moved a few things around and added some debugging. See the tips below and run my version of your rule to see if you can catch the area that is not working correctly.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

A couple of quick tips:

 

  • With Inventor 2019 and 2020 (maybe 2018? i can't recall).. you can use the ilogic Logger to report information as your rule runs.
  • For trouble shooting add Catch Ex as Exception and then return that to the ilogic Logger as in this example to show you what the Try/Catch issue is... see example below

 

Click the + sign as shown, and then select iLogic Log to bring up the logger

 

image.png

 

image.png

 

 
' Set a reference to the drawing document.' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheets As Sheets
Dim Sheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

Dim oPartList As PartsList
'try and get the parts list from the table of this sheet
Try     
	'iterate trough each sheet
	Dim i As Long
	For i = 1 To oDrawDoc.Sheets.Count
		If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
	Next    
	oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
	Logger.Info("parts list found on: " & i)
Catch
	MessageBox.Show("Can not continue, no parts list found", "iLogic")
	Return 'exit rule because no parts list is found
End Try


For Each oSheet In oDrawDoc.Sheets
	'For Each oSheet In oSheets
	oViews = oSheet.DrawingViews
	For Each oView In oViews
		Logger.Info("-------------")
		Logger.Info(oView.Name)
		Logger.Info(oView.ViewType.ToString)
		If Not oView.ViewType = DrawingViewTypeEnum.kProjectedDrawingViewType
			'Get the full filename Of the view model
			Dim oModelFileName As String
			oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
			Logger.Info("oModelFileName: " & oModelFileName)
			
			' Iterate through the contents of the parts list.
			Dim j As Long
			For j = 1 To oPartList.PartsListRows.Count
				' Get the current row.
				Dim oRow As PartsListRow
				oRow = oPartList.PartsListRows.Item(j)
				'get filename of model in row
				Dim oRowFileName As String
				oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
				
				'compare the filenames
				'Performs a text comparison, based on a case-insensitive text sort order
				'If strings equal returns 0
				If StrComp(oModelFileName, oRowFileName, CompareMethod.Text) = 0 Then 
					Logger.Info(" oRowFileName: " & oRowFileName)
				
					'Show the view label
					oView.ShowLabel = True
					
					Try
					'Get the value of Item from the Parts List
					'Row name needs to be case sensitive or use 1 for first 2 for second etc.
					oCell  = oPartList.PartsListRows.Item(j).Item("Item") 
					'get the value of text in cell
					Dim oItemValue As String
					oItemValue = oCell.Value					

					'format the text first line
					oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"
					'format the text second line
					oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
					
					'add to the view label
					oView.Label.FormattedText = oStringItem & oStringScale
					Catch ex As Exception
						Logger.Error(ex.Message)
					End Try
				End If  
			Next
		End If
	Next
Next

 

 

 

 

 

EESignature

Message 13 of 15

Curtis_Waguespack
Consultant
Consultant

Also just as a tip, programming questions of this type are better asked on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I've requested that the moderators move this post to that forum for you.

EESignature

0 Likes
Message 14 of 15

mcgyvr
Consultant
Consultant

@Curtis_Waguespack  Thanks.. You saved me the trouble I was going to go through in a few minutes after lunch..

Also showed me a few tricks I haven't gotten around to looking at with the logger..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 15 of 15

ganesh_omkaar
Contributor
Contributor

If position number change then how to deal with l logic code, (need to delet position number manually ) & then excute code . For multibody concept need to place first part on drawing 

0 Likes