Trying to add the latest revision number to my drawing number

Trying to add the latest revision number to my drawing number

Pknapp
Explorer Explorer
753 Views
9 Replies
Message 1 of 10

Trying to add the latest revision number to my drawing number

Pknapp
Explorer
Explorer

I'm trying to add the latest revision number from my revision table to the end of my drawing number. Right now it is set to pull in from a manually entered field in an excel file. Here is what I have

Public Sub UpdateTitleBlock()
'On Error Resume Next
Dim titleB, boxesB, textB As textBox
Dim bRet As Boolean
Dim PDFAddIn As TranslatorAddIn
Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
If drawingB Is Nothing Then
Set drawingB = ThisApplication.ActiveDocument
End If
Dim sheetsB As Sheets
Set sheetsB = drawingB.Sheets
Dim sheetB As sheet
Dim PromptProp() As Variant
Dim rev As String
Dim jNum As String
Dim dScale As Double
Dim draw As String
Dim shtSizeDesc As String
Dim iPos As Long
Dim sheetName As String
Const numSize As Integer = 2 'Numer of digits in sheet number at end of drawing number
Const revNote As String = "<REV>"
Const drawNum As String = "<DRAWING NO>"
Const jobNum As String = "<JOB NO>"
Const shtNumber As String = "<SHEET NO>"
Const shtTotal As String = "<SHEET NO TOTAL>"
Const shtScale As String = "<PLOT SCALE>"
Const oldDwgTB As String = "<AUTHOR>"
Const shtSize As String = "<DWG SIZE>"

xlArray PromptProp
drawingB.Update
'Call Update_TitleBlock

For Each sheetB In sheetsB 'rotates through each sheet
sheetB.Activate
sheetB.Update

Dim oDrgViews As DrawingViews
Set oDrgViews = sheetB.DrawingViews
Dim oDrgView As DrawingView
For Each oDrgView In oDrgViews 'rotates through each view making sure they are up to date.
If oDrgView.IsRasterView() = True Then
Debug.Print oDrgView.IsRasterView() & "is raster."
End If
oDrgView.IsRasterView() = False
Next

Set titleB = sheetB.TitleBlock
Set boxesB = titleB.Definition.Sketch.TextBoxes

For Each textB In boxesB
If textB.Text = oldDwgTB Then
Call UpdateTB 'Check for old Title Block
Exit For
End If
If textB.Text = shtSize Then
shtSizeDesc = sheetB.Size
If shtSizeDesc = 9988 Then
Call titleB.SetPromptResultText(textB, "B")
ElseIf shtSizeDesc = 9990 Then
Call titleB.SetPromptResultText(textB, "D")
ElseIf shtSizeDesc = 9989 Then
Call titleB.SetPromptResultText(textB, "C")
ElseIf shtSizeDesc = 9987 Then
Call titleB.SetPromptResultText(textB, "A")
ElseIf shtSizeDesc = 9991 Then
Call titleB.SetPromptResultText(textB, "E")
Else
Call titleB.SetPromptResultText(textB, "-")
End If
End If
Next

If UBound(PromptProp) > 1 Then
Dim i As Long, j As Boolean
For i = LBound(PromptProp) To UBound(PromptProp) 'Enter items from Excel into drawing border.
If Not IsEmpty(PromptProp(i, 2)) Then
For Each textB In boxesB
If textB.Text = PromptProp(i, 1) Then
Call titleB.SetPromptResultText(textB, PromptProp(i, 2))
End If
If textB.Text = jobNum Then
jNum = titleB.GetResultText(textB)
End If
Next
End If
Next

For Each textB In boxesB
If textB.Text = revNote Then
rev = titleB.GetResultText(textB)
End If

Next
For Each textB In boxesB
If textB.Text = drawNum Then 'Checks for drawing number sheet and revision
iPos = InStrRev(sheetB.Name, ":")
sheetName = Right(sheetB.Name, Len(sheetB.Name) - iPos)
If CInt(sheetName) < 10 Then 'add zero if sheet num less than 10 to keep 2 digit code
sheetName = "0" & sheetName
End If
draw = titleB.GetResultText(textB)
If Len(draw) < 4 Then 'If drawing is small than 3(01a) then use filename
draw = drawingB.FullFileName
draw = Right(draw, Len(draw) - InStrRev(drawingB.FullFileName, "\"))
End If
'Debug.Print Len(draw)
draw = Left(draw, InStrRev(draw, "-"))
'*NO LONGER NEEDED If (Len(jNum) > 1) And (Len(draw) > 1) Then 'Adds Job number to begining of drawing number
'Name now updated by file name draw = Right(draw, Len(draw) - InStr(draw, "-") + 1)
' 'Debug.Print Mid(draw, 2, 1) & IsNumeric(Mid(draw, 2, 1))
' If IsNumeric(Mid(draw, 2, 1)) = True Then
' draw = Right(draw, Len(draw) - InStr(2, draw, "-") + 1)
' End If
' draw = jNum & draw
' End If
'Debug.Print draw
draw = draw & sheetName & rev
Call titleB.SetPromptResultText(textB, draw)
ElseIf textB.Text = shtNumber Then
iPos = InStrRev(sheetB.Name, ":")
sheetName = Right(sheetB.Name, Len(sheetB.Name) - iPos)
Call titleB.SetPromptResultText(textB, sheetName)
ElseIf textB.Text = shtTotal Then
Call titleB.SetPromptResultText(textB, sheetsB.Count)
ElseIf textB.Text = shtScale Then
'If titleB.GetResultText(textB) = "" Then
Call titleB.SetPromptResultText(textB, sheetB.DrawingViews.Item(1).ScaleString)
'End If
End If
Next
Else
For Each textB In boxesB
If textB.Text = revNote Then
rev = titleB.GetResultText(textB)
End If
Next
End If
Next

drawingB.Save2

Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
If PDFAddIn.HasSaveCopyAsOptions(drawingB, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4
End If
oDataMedium.filename = SaveNameRev(drawingB, "01", rev, ".pdf")
If IsFileOpen(oDataMedium.filename) = False Then
Call PDFAddIn.SaveCopyAs(drawingB, oContext, oOptions, oDataMedium)
Else
MsgBox "File OPEN, please close " & oDataMedium.filename & " and run again."
End If
Call WriteSheetMetalDXF(drawingB, rev)

Set drawingB = Nothing
Set titleB = Nothing
Set boxesB = Nothing
'Call isOpen
End Sub

 

0 Likes
754 Views
9 Replies
Replies (9)
Message 2 of 10

rhasell
Advisor
Advisor

Hi

 

Do you need it from the spreadsheet? (If so, I can't help, my skills aren't good enough)

 

Otherwise, why don't you use the revision from  iProperties?

Here is a snippet of my code, looking at your code I am pretty sure you can work it out, as yours is pretty involved.

If you need the entire rule, it's no problem.

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oDocument = ThisApplication.ActiveDocument
	oFolder ="d:\data\1 EXPORT"
	oDataMediumPDF.FileName =oFolder + "\" + oFileName & "[" & oRevNum & "]" & ".pdf"
If System.IO.File.Exists(oDataMediumPDF.FileName) Then
	 oChoice=MessageBox.Show(oDataMediumPDF.FileName & " Already Exists - Overwrite?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		If oChoice=7
				Return
			Else
	End If
End If	
	
'''--- Publish document.
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumPDF)
Beep
MessageBox.Show("Done!", "Title")

 

Reg
2026.1
0 Likes
Message 3 of 10

Pknapp
Explorer
Explorer
No I don't want to pull it from the spreadsheet I want to pull it from the revision table in the drawing


0 Likes
Message 4 of 10

Pknapp
Explorer
Explorer

I also didn't write the code for this so I really don't know the best way to implement this

 

0 Likes
Message 5 of 10

rhasell
Advisor
Advisor

Here is copy of my rule.

 

It will Create a PDF file in the "d:\data\1 Export" folder, but you can change it to suit your needs.

'Date: 26.09.2016
'Author: Reg Hasell
' Version 1.0
'
'It will Do a very basic check to see if the file already exists, (I did not want to slow the process down too much
'It will then create a PDF file in the export directory.
'The major benefit is that it will also add the current Revision to the filename.

' Future devlopment will also update the Revision table.
'With a prompted date.

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
	Dim oPDFAddIn As TranslatorAddIn
	oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	
	Dim oDocument As Document
	oDocument = ThisApplication.ActiveDocument
	
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	Dim oDataMediumPDF As DataMedium
    oDataMediumPDF = ThisApplication.TransientObjects.CreateDataMedium

'--PDF settings---
'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
If oPDFAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 4800
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
End If
'---End PDF settings

'---
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oDocument = ThisApplication.ActiveDocument
	oFolder ="d:\data\1 EXPORT"
	oDataMediumPDF.FileName =oFolder + "\" + oFileName & "[" & oRevNum & "]" & ".pdf"
'MessageBox.Show(oDataMediumDWG.FileName, "Title")
If System.IO.File.Exists(oDataMediumPDF.FileName) Then
	 oChoice=MessageBox.Show(oDataMediumPDF.FileName & " Already Exists - Overwrite?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		If oChoice=7
		'MessageBox.Show("exit", "Title")
				Return
			Else
		'MessageBox.Show("Overwrite", "Title")
	End If
End If	
	
'''--- Publish document.
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumPDF)
Beep
MessageBox.Show("Done!", "Title")
Reg
2026.1
0 Likes
Message 6 of 10

rhasell
Advisor
Advisor

I thought I would add my rule to export a DWG file as well.

 

The difference in this one, is the use of and "ini" file This you will have to change to suit yourself. (As well as the directory)

'Date: 26.09.2016
'Author: Reg Hasell
' Version 1.0
'
'It will Do a very basic check to see if the file already exists, (I did not want to slow the process down too much
'It will then Create a DWG file in the export directory.
'The major benifit is that it will also add the current Revision to the filename.

' Future devlopment will also update the Revision table.
'With a prompted date.

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
	Dim DWGAddIn As TranslatorAddIn
	DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
	Dim oDocument As Document
	oDocument = ThisApplication.ActiveDocument
	
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMediumDWG As DataMedium
    oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium
'---
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oDocument = ThisApplication.ActiveDocument
'oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
	
		Dim strIniFile As String
        strIniFile = "d:\data\2016-acadexport-[jun16]-2.ini"
        oOptions.Value("Export_Acad_IniFile") = strIniFile

	oFolder ="d:\data\1 EXPORT"
	oDataMediumDWG.FileName =oFolder + "\" + oFileName & "[" & oRevNum & "]" & ".dwg"
If System.IO.File.Exists(oDataMediumDWG.FileName) Then
	 oChoice=MessageBox.Show(oDataMediumDWG.FileName & " Already Exists - Overwrite?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		If oChoice=7
		'MessageBox.Show("exit", "Title")
				Return
			Else
		'MessageBox.Show("Overwrite", "Title")
	End If
End If	
	
'''--- Publish document.
DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDWG)
Beep
MessageBox.Show("Done!", "Title")

 

 

Reg
2026.1
0 Likes
Message 7 of 10

Anonymous
Not applicable

If that doesnt work, here is the rule I use to add "stuff" to Part number (PN) as my dwg number. you can simply pull the iproperty "revision" form the dwg iproperties and add it to your PN instead of the "stuff" as below, i think it's iproperties.value("project", "revision number").

 

This code pulls from the first model that is loaded onto your dwg, so you'll have to make sure the ipt has iproperties filled out. This also assumes that your dwg # in your title block is linked to the part number iproperty. 

 

oViewModelName = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedFileDescriptor.FullFileName 'retrieving filename of loaded model in first dwg view; 
fname = System.IO.Path.GetFileName(oViewModelName) 'setting fname to the retrieved filename

PN = iProperties.Value(fname, "Project", "part number")

iProperties.Value("Project", "part number") = PN + "stuff"

ThisApplication.ActiveDocument.update

 

 

0 Likes
Message 8 of 10

Pknapp
Explorer
Explorer

I'm running this as a macro not as iLogic

0 Likes
Message 9 of 10

Anonymous
Not applicable

 

You should be able to accomplish the same thing with the API, just takes a little more finesse but the concept is the same.

0 Likes
Message 10 of 10

Anonymous
Not applicable

Did you get this ironed out?

0 Likes