Revsion table Auto-add

Revsion table Auto-add

josh.linares-stanley
Enthusiast Enthusiast
990 Views
6 Replies
Message 1 of 7

Revsion table Auto-add

josh.linares-stanley
Enthusiast
Enthusiast

Hi,

I have the script below which adds a neat revision cloud around my drawing part view which works great. I'd like to add some additional layers of functionality to really speed things up:

1. Once a view is selected - part number & sheet number is added to active revsion row in this format "PART NUMBER (SHT #)". The sheet number should update should it change when drawing is updated. Possibly done in conjunction with an iTrigger?

2.  If the same part is selected twice, it does not re-add it to the table.

 

Unfortunately My iLogic isn't currently quite where it needs to be to write this from scratch but i should be able to work with something if someone gets me on the right track.

 

Many thanks in advance

Public Sub Main
	mystart:
    Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View") 
	On Error GoTo myexit
    Dim sketch As DrawingSketch = view.Sketches.Add()
    Dim cp = sketch.SheetToSketchSpace(view.Position)
    Dim blue As Color = ThisApplication.TransientObjects.CreateColor(0, 0, 255)
	Dim offSetFromView As Double = 2
    sketch.Edit()
	oScale = view.Scale
	sketch.Name="REVISION CLOUD"
    Dim lines = CreateRectangle(sketch, cp, view.Width/oScale + offSetFromView, view.Height/oScale + offSetFromView)
    SetLayer(lines, LineTypeEnum.kDashedLineType, 0.05, blue)
    sketch.ExitEdit()
	GoTo mystart
	myexit:
End Sub

Public Sub SetLayer(lines As SketchEntitiesEnumerator, LineType As LineTypeEnum, LineWeight As Double, color As Color)

    For Each line As SketchEntity In lines
        Line.Layer.LineType = LineTypeEnum.kDashedLineType
        Line.Layer.LineWeight = LineWeight
        Line.Layer.Color = color
    Next
End Sub

Public Function CreateRectangle(Sketch As DrawingSketch, cp As Point2d, w As Double, h As Double) As SketchEntitiesEnumerator
    Dim oTg = ThisApplication.TransientGeometry
    Dim p1 As Point2d = cp.Copy()
    p1.TranslateBy(oTg.CreateVector2d(w / 2, h / 2))

    Dim p3 = p1.Copy()
    p3.TranslateBy(oTg.CreateVector2d(-w, -h))

    Dim lines = Sketch.SketchLines.AddAsTwoPointRectangle(p1, p3)
    Return lines
End Function

 

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

A.Acheson
Mentor
Mentor
Accepted solution

Here is additional sub routines that should achieve a portion of what your looking to do. The cells might populate incorrectly on your end so you may need to adjust the cell number per your revision style. I would suggest you text on a test drawing and adjust the revision style name "Revision Table (ANSI)" as needed. 

 

Unfortunately the auto adjust sheet name wont be possible (at least not easily) as the sheet number is just text and not an updatable formatted text attribute. Putting dynamic names into rev blocks would be best avoided for this very reason. 

 

Public Sub Main
	mystart:
    Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View") 
	
	On Error GoTo myexit
    Dim sketch As DrawingSketch = view.Sketches.Add()
    Dim cp = sketch.SheetToSketchSpace(view.Position)
    Dim blue As Color = ThisApplication.TransientObjects.CreateColor(0, 0, 255)
	Dim offSetFromView As Double = 2
    sketch.Edit()
	oScale = view.Scale
	sketch.Name="REVISION CLOUD"
    Dim lines = CreateRectangle(sketch, cp, view.Width/oScale + offSetFromView, view.Height/oScale + offSetFromView)
    SetLayer(lines, LineTypeEnum.kDashedLineType, 0.05, blue)
    sketch.ExitEdit()
	Call RevisionBlock(view)
	GoTo mystart
	myexit :
	
	
	
End Sub

Public Sub SetLayer(lines As SketchEntitiesEnumerator, LineType As LineTypeEnum, LineWeight As Double, color As Color)

    For Each line As SketchEntity In lines
        Line.Layer.LineType = LineTypeEnum.kDashedLineType
        Line.Layer.LineWeight = LineWeight
        Line.Layer.Color = color
    Next
End Sub

Public Function CreateRectangle(Sketch As DrawingSketch, cp As Point2d, w As Double, h As Double) As SketchEntitiesEnumerator
    Dim oTg = ThisApplication.TransientGeometry
    Dim p1 As Point2d = cp.Copy()
    p1.TranslateBy(oTg.CreateVector2d(w / 2, h / 2))

    Dim p3 = p1.Copy()
    p3.TranslateBy(oTg.CreateVector2d(-w, -h))

    Dim lines = Sketch.SketchLines.AddAsTwoPointRectangle(p1, p3)
    Return lines
End Function


Sub RevisionBlock(view As DrawingView)

'Change Revision Table Style
'https://forums.autodesk.com/t5/inventor-customization/ilogic-rule-to-switch-revision-table-sizes-defined-in-styles/td-p/3209372
'https://forums.autodesk.com/t5/inventor-customization/creating-sheet-scope-revision-table-using-ilogic/td-p/6282070


	Dim oDrawDoc As DrawingDocument 
	oDrawDoc = ThisDrawing.Document
	
	Dim oSheet As Sheet
	oSheet = oDrawDoc.ActiveSheet
	
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oTablePt As Point2d = oTG.CreatePoint2d(0, 0)'loosly position Table
	Dim oRevTable As RevisionTable
	
	Dim oDoc As Document
	oDoc = view.ReferencedDocumentDescriptor.ReferencedDocument
	
	Dim FileName, PN, SN As String
	FileName = IO.Path.GetFileName(oDoc.FullDocumentName)
	PN = iProperties.Value(FileName, "Project", "Part Number")
	SN = oSheet.Name
	'Check which revision Table To add, Only needed If Styles are different

	oRevStyle = oDrawDoc.StylesManager.RevisionTableStyles.Item("Revision Table (ANSI)")
	
	']
	
	If oSheet.RevisionTables.Count = 1 Then
 
		Call Positiontable(oTablePt,oSheet)
		oRevTable = oSheet.RevisionTables.Item(1)
		
        oRevTable.Style = oRevStyle 'Change RevTable Style
		Dim oRow As RevisionTableRow 
		oRow = oRevTable.RevisionTableRows.Item(oRevTable.RevisionTableRows.Count) 
			
			booleanParam = InputRadioBox("Pick One", "Continue Editing Current REV",  "Add REV",True, Title := "Revision Box Options")'Enter 1st row Contents
			If booleanParam = True
				RevisionTableContents(oRow,PN,SN)
			ElseIf booleanParam = False	
				Dim oRows As RevisionTableRows = oRevTable.RevisionTableRows
				oRows.Add()
				oRow = oRevTable.RevisionTableRows.Item(oRevTable.RevisionTableRows.Count)'Get current Row
           		 RevisionTableContents(oRow,PN,SN)
			End If

	ElseIf oSheet.RevisionTables.Count = 0 Then
		
		Dim oRTBs As RevisionTables 
		oRTBs = oSheet.RevisionTables 

		Dim oRTB As RevisionTable 'add a new table
		oRTB = oRTBs.Add2(oTablePt, False, True, True, "0" )
		Call Positiontable(oTablePt,oSheet)'Position Table after initial insert
		oRevTable = oSheet.RevisionTables.Item(1)'get table reference
		oRevTable.Style = oRevStyle 'Change RevTable Style
		
		Dim oRow As RevisionTableRow 
		oRow = oRevTable.RevisionTableRows.Item(oRevTable.RevisionTableRows.Count) 
		If oRow.IsActiveRow Then 
			
		    Call RevisionTableContents(oRow,PN,SN)'Enter 1st row Contents
			oRTB.UpdatePropertyToRevisionNumber = True 'ensure rev block is set to write to iProperty, This can be modified in two places in the editor and in the template when placing
		End If

	End If
End Sub

	
	Private Sub	Positiontable( oTablePt As Point2d,oSheet As Sheet)

Dim oRevTableItem As RevisionTable
oRevTableItem = oSheet.RevisionTables.Item(1) 

Dim oWidthRevTable As Double
oWidthRevTable = oRevTableItem.RangeBox.MaxPoint.X - oRevTableItem.RangeBox.MinPoint.X

Dim oHeightRevTable As Double
oHeightRevTable = oRevTableItem.RangeBox.MaxPoint.Y - oRevTableItem.RangeBox.MinPoint.Y

oTablePt = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Border.RangeBox.MaxPoint.X - oWidthRevTable, oSheet.TitleBlock.RangeBox.MaxPoint.Y + oHeightRevTable)

oRevTableItem.Position = oTablePt
End Sub
	']
	
			

	
	 Sub RevisionTableContents(oRow,PN,SN)
		 	']
		'[Revision COL 2
'		Dim MyArrayList2 As New ArrayList
'		MyArrayList2.Add("AA")
'		oArray2 = InputListBox("Select one:", MyArrayList2, "", "iLogic", "Drawn By")
		
'		If oArray2 = "" Then
'		Else
'			Dim oCell2 As RevisionTableCell = oRow.Item(2)
'			oCell2.Text = oArray2
'		End If
		 
 		Dim oCell3 As RevisionTableCell = oRow.Item(3)
		'Set it equal to the the current date, date format change from Computer default        
		oCell3.Text= DateTime.Now.ToString("dd-MM-yyyy")
		 
		'[Revision COL 4
		Dim MyArrayList4 As New ArrayList
		MyArrayList4.Add("FOR CUSTOMER REVIEW")
		MyArrayList4.Add("FOR CUSTOMER APPROVAL")
		MyArrayList4.Add("INITIAL RELEASE")	
		MyArrayList4.Add("ENTER CUSTOM COMMENT")
		
		oArray4 = InputListBox("Select one:", MyArrayList4, "", "iLogic","Choices"  )
		
		If oArray4 = "" Then
		
	    ElseIf oArray4 = "ENTER CUSTOM COMMENT" Then
		
			oInput4 = UCase(InputBox("What did you change?", "REV","Part#: "& PN &"SN: " & SN))
		
			If oInput4 = "" Then
			Else
				Dim oCell4 As RevisionTableCell = oRow.Item(4)
				oCell4.Text = oInput4
			End If
		Else
			Dim oCell4 As RevisionTableCell = oRow.Item(4)
			oCell4.Text = oArray4	
		End If	
			
												
		']
		'[Revision COL 5	
		Dim MyArrayList5 As New ArrayList
		MyArrayList5.Add("AA")
		oArray5 = InputListBox("Select one:", MyArrayList5, "", "iLogic", "Checked By ")
		
		If oArray5 = "" Then
		Else
			Dim oCell5 As RevisionTableCell = oRow.Item(5)
			oCell5.Text = oArray5
		End If
		
		End Sub
	']

 

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

josh.linares-stanley
Enthusiast
Enthusiast

Great, Thanks for the response - I can definately work with this. It doesn't quite appear to work with the revision cloud portion which i've had to remove for now -  I think it may be do to with the fact it's written so that it cycles continuously until it gets an error. ie. allows the selection of multiple view without having to re-run the script.

Also, It currently writes the part number and sheet as required but seems to overwrite previous entries in the rev box. My preferance would be that it writes in a line above. example below;

joshlinaresstanley_1-1643102548956.png

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

To deal with escaping the error you could check if object is nothing to exit a do loop. This happens when you press the esc key. See here for an example. 

 

 

In order to add new value to previous cell value. The below should work. vblf is code for enter when in the cell so will jump to next line. 

 

oCell4.Text = oInput4 & vblf & oCell4.Text

 

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

josh.linares-stanley
Enthusiast
Enthusiast

Nice tip, Thanks. I have managed to get the majority of this working now for our drawing format, it's pretty neat - only aspect I'd like to have is for it to work with a revision table present on only 'sheet one' instead of everysheet. Spent a large portion of my evening implementing work-arounds to achieve this but I get an error message. Any ideas?

Cheers

 

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor

So let's say revision table is on sheet 1 and the rev cloud is happening on different sheets. You should be able to switch reference of the sheet wherever it is called to be used.

 

Dim oPLsheet As Sheet
	oPLsheet = oDrawDoc.Sheets(1)
oRevTable = oPLsheet.RevisionTables.Item(1)'get table reference 

 I am not sure if you physically need to be on  sheet 1 and make it then the active sheet to populate the data but give it a try as is. 

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

josh.linares-stanley
Enthusiast
Enthusiast

Wasn't sure where to add those lines. I instead added the following:

oDoc = ThisDoc.Document
oSheetidentifier = Mid(oDoc.ActiveSheet.Name, InStr(1, oDoc.ActiveSheet.Name, ":") + 1)
If oSheetidentifier > 1 Then
oRevTable.Delete

Essentially means the script does add a revision table to the active sheet - which provides a handy preview. Then deletes the table if on anything other than sheet 1 . Possibly isn't the most elegant method but seems to work okay. Thanks for your help!

0 Likes