Need Help updating template and old drawings ilogic

Need Help updating template and old drawings ilogic

drafting1
Contributor Contributor
1,962 Views
9 Replies
Message 1 of 10

Need Help updating template and old drawings ilogic

drafting1
Contributor
Contributor

Hi All

 

I am currently updating a lot of old drawings and updating our standard template.

 

I have done a ilogic to create a pdf and dxf file on close set as extrernal

 

oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'query user
question = MessageBox.Show("Create PDF?", "Create PDF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

'set condition based on answer
            If question = vbYes Then
			
'------start of iLogic-------
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
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

'get PDF target folder path
oFolder = oPath & "\" & "PDFDXF"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".pdf"
MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

Else If question = vbNo Then
End If

'query user
question = MessageBox.Show("Create DXF?", "Create DXF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

'set condition based on answer
            If question = vbYes Then

'get DXF target folder path
oFolder = oPath & "\" & "PDFDXF"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

 'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".dxf"
MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
'Publish document
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

Else If question = vbNo Then
End If

I have also got a ilogic to update an old drawing title block and styles to what is in the template. The issue is when I run it it then wants to run the dxf and pdf ilogic aswell?

 

Option Explicit

Sub Main

Dim oTargetDoc, oSourceDoc As DrawingDocument
Dim oTBdef As TitleBlockDefinition
Dim oTBdefs As TitleBlockDefinitions
Dim oBorderDef As BorderDefinition
Dim oBorderDefs As BorderDefinitions
Dim oSymbol As SketchedSymbolDefinition
Dim oSymbols As SketchedSymbolDefinitions
Dim oPrompt As String

If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
	MsgBox("This rule may only be run on drawing documents!",vbOKOnly,"Update Titleblocks")
	Exit Sub
End If

oTargetDoc = ThisDrawing.Document

oPrompt = MsgBox("Update Titleblocks and Styles?",vbYesNo,"Update Titleblocks")
Select Case oPrompt
Case vbNo
	Exit Sub
Case vbYes
	oSourceDoc = ThisApplication.Documents.Open("C:\_Vault\Inventor Templates\Standard.idw", False)
	oTargetDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal
End Select

oTBdefs = oSourceDoc.TitleBlockDefinitions
oBorderDefs = oSourceDoc.BorderDefinitions
oSymbols = oSourceDoc.SketchedSymbolDefinitions

For Each oTBdef In oTBdefs
	Try
		If oTBdef.Name <> "ANSI - Large" Then
			oTBdef.CopyTo(oTargetDoc, True)
		End If
	Catch
		MsgBox("Unknown error in copy title block for " & Chr(34) & oTBdef.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next
For Each oBorderDef In oBorderDefs
	Try
		If oBorderDef.Name <> "Default Border" Then
			oBorderDef.CopyTo(oTargetDoc, True)
		End If
	Catch
		MsgBox("Unknown error in copy border definition for " & Chr(34) & oBorderDef.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next
For Each oSymbol In oSymbols
	Try
		oSymbol.CopyTo(oTargetDoc, True)
	Catch
		MsgBox("Unknown error in copy sketched symbol for " & Chr(34) & oSymbol.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next

oSourceDoc.Close()
End Sub

Is it possible to get it not to do this?

In the update title block ilogic can I get it to also add the create pdf and dxf to a trigger automatically?

 

The last thing I would like to do is set the drawing Iproperties to match the model iproperties.

 

Currently I have to manually go Tools -> Document settings -> Drawings -> Copy Model iProperty settings and tick copy all.

Can this be done automatically?

And update on open of drawing and save eg

I have this code

Dim oControlDef as ControlDefinition  = ThisApplication.CommandManager.ControlDefinitions.​Item("UpdateCopiedModeliPropertiesCmd")
 
oControlDef.Execute2(True)

Sorry for the long winded msg

 

Thanks,

Matt

0 Likes
Accepted solutions (1)
1,963 Views
9 Replies
Replies (9)
Message 2 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @drafting1,

 

Try the following solution provided in Forum.

 

https://forums.autodesk.com/t5/inventor-customization/run-ilogic-rule-from-another-rule/td-p/6994012

 

As Inventor API is not exposed to copy model iProperties from Drawing settings.

 

Try the following iLogic rule to copy iProperties from referenced document to Drawing document.

 

 

If (ThisDrawing.ModelDocument Is Nothing) Then Return

modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

iProperties.Value("Project", "Part Number") = iProperties.Value(modelName, "Project", "Part Number") 

iProperties.Value("Summary", "Title") = iProperties.Value(modelName, "Summary", "Title")

iProperties.Value("Summary", "Subject") = iProperties.Value(modelName, "Summary", "Subject")

iProperties.Value("Status", "Status") = iProperties.Value(modelName, "Status", "Status")

iProperties.Value("Summary", "Author") = iProperties.Value(modelName, "Summary", "Author")

iProperties.Value("Project", "Authority") = iProperties.Value(modelName, "Project", "Authority") 

iProperties.Value("Summary", "Category") = iProperties.Value(modelName, "Summary", "Category")

iProperties.Value("Status", "Checked By") = iProperties.Value(modelName, "Status", "Checked By")

iProperties.Value("Status", "Checked Date") = iProperties.Value(modelName, "Status", "Checked Date")

iProperties.Value("Summary", "Comments") = iProperties.Value(modelName, "Summary", "Comments")

iProperties.Value("Summary", "Company") = iProperties.Value(modelName, "Summary", "Company")

iProperties.Value("Project", "Cost Center") = iProperties.Value(modelName, "Project", "Cost Center") 

iProperties.Value("Project", "Creation Date") = iProperties.Value(modelName, "Project", "Creation Date") 

iProperties.Value("Project", "Description") = iProperties.Value(modelName, "Project", "Description") 

iProperties.Value("Project", "Designer") = iProperties.Value(modelName, "Project", "Designer") 

iProperties.Value("Status", "Design State") = iProperties.Value(modelName, "Status", "Design State")

iProperties.Value("Status", "Engr Approved By") = iProperties.Value(modelName, "Status", "Engr Approved By")

iProperties.Value("Status", "Engr Date Approved") = iProperties.Value(modelName, "Status", "Engr Date Approved")

iProperties.Value("Project", "Cost") = iProperties.Value(modelName, "Project", "Cost") 

iProperties.Value("Project", "Vendor") = iProperties.Value(modelName, "Project", "Vendor") 

iProperties.Value("Summary", "Keywords") = iProperties.Value(modelName, "Summary", "Keywords")

iProperties.Value("Summary", "Manager") = iProperties.Value(modelName, "Summary", "Manager")

iProperties.Value("Status", "Mfg Approved By") = iProperties.Value(modelName, "Status", "Mfg Approved By")

iProperties.Value("Status", "Mfg Date Approved") = iProperties.Value(modelName, "Status", "Mfg Date Approved")

iProperties.Value("Project", "Web Link") = iProperties.Value(modelName, "Project", "Web Link") 

iProperties.Value("Project", "Stock Number") = iProperties.Value(modelName, "Project", "Stock Number") 

iProperties.Value("Summary", "Subject") = iProperties.Value(modelName, "Summary", "Subject")

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 10

drafting1
Contributor
Contributor

That helps with some of my question.

 

In my template I have set Create PDF and DXF on close ilogic.

 

If I open an old drawing that I want to update the title block and styles I run the Update title block and styles ilogic below. The issue is whilst its doing this it then asks me if I want a PDF and dxf?

 

Option Explicit

Sub Main

Dim oTargetDoc, oSourceDoc As DrawingDocument
Dim oTBdef As TitleBlockDefinition
Dim oTBdefs As TitleBlockDefinitions
Dim oBorderDef As BorderDefinition
Dim oBorderDefs As BorderDefinitions
Dim oSymbol As SketchedSymbolDefinition
Dim oSymbols As SketchedSymbolDefinitions
Dim oPrompt As String

If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
	MsgBox("This rule may only be run on drawing documents!",vbOKOnly,"Update Titleblocks")
	Exit Sub
End If

oTargetDoc = ThisDrawing.Document

oPrompt = MsgBox("Update Titleblocks and Styles?",vbYesNo,"Update Titleblocks")
Select Case oPrompt
Case vbNo
	Exit Sub
Case vbYes
	oSourceDoc = ThisApplication.Documents.Open("C:\_Vault\Inventor Templates\Standard.idw", False)
	oTargetDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal
End Select

oTBdefs = oSourceDoc.TitleBlockDefinitions
oBorderDefs = oSourceDoc.BorderDefinitions
oSymbols = oSourceDoc.SketchedSymbolDefinitions

For Each oTBdef In oTBdefs
	Try
		If oTBdef.Name <> "ANSI - Large" Then
			oTBdef.CopyTo(oTargetDoc, True)
		End If
	Catch
		MsgBox("Unknown error in copy title block for " & Chr(34) & oTBdef.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next
For Each oBorderDef In oBorderDefs
	Try
		If oBorderDef.Name <> "Default Border" Then
			oBorderDef.CopyTo(oTargetDoc, True)
		End If
	Catch
		MsgBox("Unknown error in copy border definition for " & Chr(34) & oBorderDef.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next
For Each oSymbol In oSymbols
	Try
		oSymbol.CopyTo(oTargetDoc, True)
	Catch
		MsgBox("Unknown error in copy sketched symbol for " & Chr(34) & oSymbol.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next

oSourceDoc.Close()
End Sub
0 Likes
Message 4 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @drafting1,

 

Hoping that following iLogic code helps current situation.

 

Result = MessageBox.Show("Do you want to export to PDF and Dxf?", "PDF / DXF Export",MessageBoxButtons.YesNo)

If Result = 6 Then

	MessageBox.Show("Run the PDF and Dxf rule")
Else

	MessageBox.Show("Don't run the PDF and Dxf rule")
	
End If

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 10

drafting1
Contributor
Contributor

Sorry but that doesn't really solve the issue.

 

On my template I have this set to run on close.

 

Capture.PNG

 

When I open an old drawing that isn't the same as the current template I run the Update Title Block and Styles rule.

 

This works fine in updating the title block and styles to match the template the issue is when I click run this rule on old drawing it then asked me if I want to create a pdf and dxf.

 

Capture2.PNG

0 Likes
Message 6 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @drafting1,

 

Can you please provide old and new templates (non confidential one) to test?

 

Correct me If wrong. In old template/drawing, without asking anything create a pdf and dxf rule should work.

 

Please specify the steps followed.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 10

drafting1
Contributor
Contributor

The old template doesnt ask to create a pdf or dxf on close unless I add the trigger.

 

It is when I run the update title block and styles ilogic during the update it will also ask about pdf and dxf even though i don't have it in that code

0 Likes
Message 8 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @drafting1,

 

I got the reason, why "Created PDF and DXF" rule is calling without trigger as you say?

 

Option Explicit

Sub Main

Dim oTargetDoc, oSourceDoc As DrawingDocument
Dim oTBdef As TitleBlockDefinition
Dim oTBdefs As TitleBlockDefinitions
Dim oBorderDef As BorderDefinition
Dim oBorderDefs As BorderDefinitions
Dim oSymbol As SketchedSymbolDefinition
Dim oSymbols As SketchedSymbolDefinitions
Dim oPrompt As String

If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
	MsgBox("This rule may only be run on drawing documents!",vbOKOnly,"Update Titleblocks")
	Exit Sub
End If

oTargetDoc = ThisDrawing.Document

oPrompt = MsgBox("Update Titleblocks and Styles?",vbYesNo,"Update Titleblocks")
Select Case oPrompt
Case vbNo
	Exit Sub
Case vbYes
	oSourceDoc = ThisApplication.Documents.Open("C:\_Vault\Inventor Templates\Standard.idw", False)
	oTargetDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal
End Select

oTBdefs = oSourceDoc.TitleBlockDefinitions
oBorderDefs = oSourceDoc.BorderDefinitions
oSymbols = oSourceDoc.SketchedSymbolDefinitions

For Each oTBdef In oTBdefs
	Try
		If oTBdef.Name <> "ANSI - Large" Then
			oTBdef.CopyTo(oTargetDoc, True)
		End If
	Catch
		MsgBox("Unknown error in copy title block for " & Chr(34) & oTBdef.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next
For Each oBorderDef In oBorderDefs
	Try
		If oBorderDef.Name <> "Default Border" Then
			oBorderDef.CopyTo(oTargetDoc, True)
		End If
	Catch
		MsgBox("Unknown error in copy border definition for " & Chr(34) & oBorderDef.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next
For Each oSymbol In oSymbols
	Try
		oSymbol.CopyTo(oTargetDoc, True)
	Catch
		MsgBox("Unknown error in copy sketched symbol for " & Chr(34) & oSymbol.Name & Chr(34),vbOKOnly,"Error")
	End Try
Next

oSourceDoc.Close()
End Sub

In the above iLogic rule is for Updating title block and styles, oSourceDoc.Close() is the root cause to trigger "Created PDF & DXF" iLogic rule.

 

iLogicTrigger.png

 

As per the above image, on closing document "Created PDF & DXF" should be triggered.

 

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 10

drafting1
Contributor
Contributor

Thanks, That solved that issue.

 

So from my understanding I cannot get it auto copy the triggers from the template to old drawings?

0 Likes
Message 10 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @drafting1,

 

If issue is solved, then click on "Accept as solution".

 

Auto copying triggers is also depends on situation. In current old drawings, better to avoid auto copy of triggers.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes