Ilogic Sheet Revision, Sheet Number and Sheet Name in a table.

Ilogic Sheet Revision, Sheet Number and Sheet Name in a table.

t.adkins
Enthusiast Enthusiast
2,972件の閲覧回数
17件の返信
メッセージ1/18

Ilogic Sheet Revision, Sheet Number and Sheet Name in a table.

t.adkins
Enthusiast
Enthusiast

I am looking for a way to put sheet information into a single table.

I came across "iLogic Drawing Index from Sheet Name and Number" and it was a helpful but when I try putting in additional information in I seem to get an  error

"System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

 

thank you,

0 件のいいね
解決済み
2,973件の閲覧回数
17件の返信
返信 (17)
メッセージ2/18

WCrihfield
Mentor
Mentor

Hi @t.adkins.  After reading through the text file, I have a couple of suggestions you could look into or try out.

I would change this line:

Dim oTextBox As TextBox

to be like this:

Dim oTextBox As Inventor.TextBox

...because iLogic gets this object confused with the TextBox within a Windows Form by the same name, when you want it to be defined as an Inventor sketch TextBox.  This will also help with the 'intellisense' (iLogic's pop-up information and suggestions system within the iLogic Rule Editor dialog).

 

Also, when setting the value of the 'oRows' variable, you are using 'oDoc.Sheets.Count - 1', however, you have already specified a few lines above that point that the first sheet is not to be included in the count, so this may not be getting the correct count.  Just a thought.

Also, where you are setting the values within the 'oContents' array variable, you are using a String type variable ('sSheetRev') that you have not set a value to yet at that point in the code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 件のいいね
メッセージ3/18

t.adkins
Enthusiast
Enthusiast

hi WCrihfield

Thank you for your suggestion. I am a novice when it comes to the ways of ilogic and welcome any advice.

I actually do not want to exclude the sheet that the index table is on. trouble is when it change it to false the code fails.

I am stuck in a spot of using chunks of others work and trying to modify to meet my needs because my inexperience with ilogic or trying my hand doing it myself and loosing myself in after basic setup.   

 

I have attached what my end goal is. I feel like I am far from the goal, yet I know a few corrected lines and addition of oSheet.Revision and I could get the results.  I am wondering which way would be easier. Making a table with set  cell dimensions or making a Title block/sketch with information .

 

Any advice from you and fellow community members again is appreciated. I would rather ask for help than waste time with no results. 

 

Thank you,

0 件のいいね
メッセージ4/18

Zach.Stauffer
Advocate
Advocate

There are a few errors with your code. If you want to include the first sheet as well then obviously you don't need to exclude it or activate it, but make sure you set oRows = oDoc.Sheets.Count if you are going to include the first sheet. You also need 3 columns (rev, sheet #, and description) but you are only declaring 2 columns. Changing it to 3 columns should fix your out of index error(s).

 

As already noted, then you have to set sSheetRev before assigning its value. That is just one line, right before your table data comment. When I ran that code my sheet didn't have a revision so keep note of that.

sSheetRev = oSheet.Revision

Last, in your for each loop you don't need to test for oSheet.ExcludeFromCount. I think that will fix it for you.

0 件のいいね
メッセージ5/18

t.adkins
Enthusiast
Enthusiast
Dim oDoc As DrawingDocument 
oDoc = ThisApplication.ActiveDocument

Dim oSheet, oIndexSheet As Sheet 
Dim sSheetName, sSheetNo, sSheetRev As String
Dim oTitleBlock As TitleBlock
Dim oTextBox As Inventor.TextBox

oIndexSheet = oDoc.Sheets(1)'In order to put table on sheet 1

sSheetRev = oSheet.Revision
'[Table Setup
Dim oColumns,oRows,oCells,i As Integer
oColumns = 3
i = 0
oRows = oDoc.Sheets.Count
oCells = oColumns * oRows 'calculate number of cells

Dim oContents(oCells - 1) As String 'Minus 1 as array will start from zero
Dim oTitles(oColumns - 1) As String 'Minus 1 as array will start from zero
'Hardcoded titles 
oTitles(2) = "DESCRIPTION"
oTitles(1) = "SHEET #"
oTitles(0) = "SHEET REV"
']
For Each oSheet In oDoc.Sheets
	If oSheet.ExcludeFromCount = False Then 'Avoid processing index page
		lPos = InStr(oSheet.Revision, ":")
		sSheetRevision = Left(oSheet.Revision, lPos - 1)
		sSheetNo = Left(oSheet.No, 1)
		sSheetName = Right(oSheet.Name, 2)
		
		oTitleBlock = oSheet.TitleBlock
		
		For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
	        If oTextBox.Text = "SHEET-NAME" Then
	            Call oTitleBlock.SetPromptResultText(oTextBox, sSheetName)
			End If
	    Next
		'[Table Data
		oContents(i) = sSheetName 'Add to string 
		i = i+1
		oContents(i) = sSheetNo  'Add to string 
		i = i + 1
		oContents(i) = sSheetRev  'Add to string 
		i = i + 1
		']
	Else

	End If
Next

Dim InsP As Point2d
InsP = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)

Dim oCustomTable As CustomTable
oCustomTable = oIndexSheet.CustomTables.Add("DRAWING INDEX", InsP, oColumns, oRows, oTitles, oContents)
0 件のいいね
メッセージ6/18

t.adkins
Enthusiast
Enthusiast

Do I  need the -1 in lines 19 and 20?

 

These are my error in code as of now.

 

System.NullReferenceException: Object reference not set to an instance of an object.
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 件のいいね
メッセージ7/18

Curtis_Waguespack
Consultant
Consultant
解決済み

Hi @t.adkins ,

 

I think something like this should work for you. See the attached Inventor 2020 example drawing for reference.

 

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

 

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet, oIndexSheet As Sheet
Dim sSheetName, sSheetNo, sSheetRev As String
Dim oTitleBlock As TitleBlock
Dim oTextBox As Inventor.TextBox

oIndexSheet = oDoc.Sheets(1)'In order to put table on sheet 1

'[Table Setup
Dim oColumns, oRows, oCells, i As Integer
oColumns = 3
i = 0
oRows = oDoc.Sheets.Count - 1
oCells = oColumns * oRows 'calculate number of cells

Dim oContents(oCells - 1) As String 'Minus 1 as array will start from zero
Dim oTitles(oColumns - 1) As String 'Minus 1 as array will start from zero
'Hardcoded titles 
oTitles(2) = "DESCRIPTION"
oTitles(1) = "SHEET #"
oTitles(0) = "SHEET REV"
']


For Each oSheet In oDoc.Sheets

	If oSheet.ExcludeFromCount = True Then Continue For

	sSplit = Split(oSheet.Name, ":")
	
	sSheetName = sSplit(0)
	sSheetNo = sSplit(1)
	sSheetRev = oSheet.Revision
	oTitleBlock = oSheet.TitleBlock

	For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
		If oTextBox.Text = "SHEET-NAME" Then
			Call oTitleBlock.SetPromptResultText(oTextBox, sSheetName)
		End If
	Next
	'[Table Data
	oContents(i) = sSheetRev 'Add to string 
	i = i + 1
	oContents(i) = sSheetNo  'Add to string 
	i = i + 1
	oContents(i) = sSheetName  'Add to string 
	i = i + 1
	']

Next

Dim InsP As Point2d
InsP = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)

Dim oCustomTable As CustomTable
oTableName = "DRAWING INDEX"
Try : oIndexSheet.CustomTables.Item(1).Delete : Catch : End Try

oCustomTable = oIndexSheet.CustomTables.Add(oTableName, InsP, oColumns, oRows, oTitles, oContents)

 

EESignature

0 件のいいね
メッセージ8/18

t.adkins
Enthusiast
Enthusiast

This is amazing . Is there an easy way to add the sheet 1 to the table?   I feel like it has to do with line 15, 18,and 19.

0 件のいいね
メッセージ9/18

Curtis_Waguespack
Consultant
Consultant

Hi @t.adkins 

 

In the example I posted Sheet1 was set to be excluded from the count, so the code is skipping that sheet, and it is adjusting the count by -1, using these 2 lines:

 

oRows = oDoc.Sheets.Count - 1
If oSheet.ExcludeFromCount = True Then Continue For

Curtis_Waguespack_0-1657045178402.png

 

 

 

To include Sheet 1, even though it is excluded, we could use something like this example below.

 

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

 

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet, oIndexSheet As Sheet
Dim sSheetName, sSheetNo, sSheetRev As String
Dim oTitleBlock As TitleBlock
Dim oTextBox As Inventor.TextBox

oIndexSheet = oDoc.Sheets(1)'In order to put table on sheet 1

'[Table Setup
Dim oColumns, oRows, oCells, i As Integer
oColumns = 3
i = 0
oRows = oDoc.Sheets.Count
oCells = oColumns * oRows 'calculate number of cells

Dim oContents(oCells - 1) As String 'Minus 1 as array will start from zero
Dim oTitles(oColumns - 1) As String 'Minus 1 as array will start from zero
'Hardcoded titles 
oTitles(2) = "DESCRIPTION"
oTitles(1) = "SHEET #"
oTitles(0) = "SHEET REV"
']


For Each oSheet In oDoc.Sheets

	sSplit = Split(oSheet.Name, ":")

	Try : sSheetName = sSplit(0) : Catch : sSheetName = oSheet.Name : End Try
	Try : sSheetNo = sSplit(1) : Catch : sSheetNo = "-" : End Try
		
	sSheetRev = oSheet.Revision

	Try 'to get title block
		oTitleBlock = oSheet.TitleBlock

		For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
			If oTextBox.Text = "SHEET-NAME" Then
				Call oTitleBlock.SetPromptResultText(oTextBox, sSheetName)
			End If
		Next
	Catch 
		'handle error when no title block is on the sheet
	End Try
	
	'[Table Data
	oContents(i) = sSheetRev 'Add to string 
	i = i + 1
	oContents(i) = sSheetNo  'Add to string 
	i = i + 1
	oContents(i) = sSheetName  'Add to string 
	i = i + 1
	']

Next

Dim InsP As Point2d
InsP = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)

Dim oCustomTable As CustomTable
oTableName = "DRAWING INDEX"

Try : oIndexSheet.CustomTables.Item(1).Delete : Catch : End Try

oCustomTable = oIndexSheet.CustomTables.Add(oTableName, InsP, oColumns, oRows, oTitles, oContents)

EESignature

0 件のいいね
メッセージ10/18

t.adkins
Enthusiast
Enthusiast

Is there a way to make the sheet that the table on show as sheet one instead of "-" ?

0 件のいいね
メッセージ11/18

Curtis_Waguespack
Consultant
Consultant
解決済み

Hi @t.adkins 

 

So to clarify:

 

You have sheet 1 ( the index sheet containing the table) set to be excluded from the count, but you want it to be listed in the table as sheet 1.

 

If that is correct, then something like this would work.

 

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

 

Curtis_Waguespack_0-1657047135342.png

 

 

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

Dim oSheet, oIndexSheet As Sheet
Dim sSheetName, sSheetNo, sSheetRev As String
Dim oTitleBlock As TitleBlock
Dim oTextBox As Inventor.TextBox

oIndexSheet = oDoc.Sheets(1)'In order to put table on sheet 1

'[Table Setup
Dim oColumns, oRows, oCells, i As Integer
oColumns = 3
i = 0
oRows = oDoc.Sheets.Count
oCells = oColumns * oRows 'calculate number of cells

Dim oContents(oCells - 1) As String 'Minus 1 as array will start from zero
Dim oTitles(oColumns - 1) As String 'Minus 1 as array will start from zero
'Hardcoded titles 
oTitles(2) = "DESCRIPTION"
oTitles(1) = "SHEET #"
oTitles(0) = "SHEET REV"
']

iCount = 1
For Each oSheet In oDoc.Sheets

	sSplit = Split(oSheet.Name, ":")

	Try : sSheetName = sSplit(0) : Catch : sSheetName = oSheet.Name : End Try
	sSheetNo = iCount
		
	sSheetRev = oSheet.Revision

	Try 'to get title block
		oTitleBlock = oSheet.TitleBlock

		For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
			If oTextBox.Text = "SHEET-NAME" Then
				Call oTitleBlock.SetPromptResultText(oTextBox, sSheetName)
			End If
		Next
	Catch 
		'handle error when no title block is on the sheet
	End Try
	
	'[Table Data
	oContents(i) = sSheetRev 'Add to string 
	i = i + 1
	oContents(i) = sSheetNo  'Add to string 
	i = i + 1
	oContents(i) = sSheetName  'Add to string 
	i = i + 1
	']

	iCount = iCount +1
Next

Dim InsP As Point2d
InsP = ThisApplication.TransientGeometry.CreatePoint2d(10, 15)

Dim oCustomTable As CustomTable
oTableName = "DRAWING INDEX"

Try : oIndexSheet.CustomTables.Item(1).Delete : Catch : End Try

oCustomTable = oIndexSheet.CustomTables.Add(oTableName, InsP, oColumns, oRows, oTitles, oContents)

 

EESignature

メッセージ12/18

t.adkins
Enthusiast
Enthusiast

This is exactly what I needed!     Unless you have a way to auto update the data in the table I think this could get any better.  Thank you again!

メッセージ13/18

Curtis_Waguespack
Consultant
Consultant

@t.adkins wrote:

This is exactly what I needed!     Unless you have a way to auto update the data in the table I think this could get any better.  Thank you again!


You could use an Event Trigger to have this trigger "Before Save" so that the rule always runs when the drawing is saved.

 

https://knowledge.autodesk.com/support/inventor/learn-explore/caas/CloudHelp/cloudhelp/2022/ENU/Inve...

 

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

EESignature

0 件のいいね
メッセージ14/18

t.adkins
Enthusiast
Enthusiast

if I am not mistaken that will just make a new table. That was my initial plan as I don't know of any other way but hey there is always a chance something has changed.

0 件のいいね
メッセージ15/18

Curtis_Waguespack
Consultant
Consultant

@t.adkins wrote:

if I am not mistaken that will just make a new table. That was my initial plan as I don't know of any other way but hey there is always a chance something has changed.


The examples I posted look for and delete the first table on oIndexSheet, and then re-creates it.

 

So, it functions as if it is just updating the table.

 

But if you need it to truly update the existing table that would be more involved.

 

EESignature

0 件のいいね
メッセージ16/18

t.adkins
Enthusiast
Enthusiast

I see what it is doing. That seems to do the trick honestly.

0 件のいいね
メッセージ17/18

tkddud711
Advocate
Advocate

I want to enter the quantity of parts for each sheet into a table,
Could you add ("Inventor User Defined Properties").Item("T-QTY").Value to the table?

0 件のいいね
メッセージ18/18

A.Acheson
Mentor
Mentor

I would suggest to create a new post for this task. It doesn't resemble the title of this post or its content. I would suggest you read the parts list/ BOM if you really want to show parts qty's. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 件のいいね