ilogic export in pdf all black but company logo in color, is possible?

ilogic export in pdf all black but company logo in color, is possible?

omvcilindri
Contributor Contributor
1,042 Views
5 Replies
Message 1 of 6

ilogic export in pdf all black but company logo in color, is possible?

omvcilindri
Contributor
Contributor

I would like to export all black drawing to PDF but with the company logo layers is it possible?
Can anyone help me?

 

‘esporta PDF in bianco e nero ma logo acolori

path_and_name = ThisDoc.PathAndFileName(False)
pdfAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

i = MessageBox.Show("Launch the viewer now?", "Title",MessageBoxButtons.YesNo)
If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If 

If pdfAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Launch_Viewer") = launchviewer
oOptions.Value("Publish_All_Component_Props") = 1
oOptions.Value("Publish_All_Physical_Props") = 1
oOptions.Value("Password") = 0
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet
' Create a Drawing View Object
''Dim layers As LayersEnumerator
''Dim oLayer As Layer

''Dim colorLayer As Layer
''		 ''Set colorLayer = layers.Item(color.Name)
''          colorLayer = layers.Item(0, 0, 0)
''For Each oLayer In oDrawDoc.StylesManager.Layers
''	             'layers = drawDoc.StylesManager.Layers
''				 'ThisDrawing.Document.StylesManager.Layers.Item.Color
''                 ThisApplication.TransientObjects.CreateColor(0, 0, 0) ' black
''				Next
Dim LayerCollection As LayersEnumerator = ThisDoc.Document.StylesManager.Layers

        Dim Layer As Layer

        'loop through LayerCollection
        For Each Layer In LayerCollection
            'assumption If DWG is in the name then alway the first 3 letters!
            'Dim layerName As String = Layer.Name
            'Dim first3Letters As String = Strings.Left(layerName, 3)
            'If first3Letters = "DWG" Then
                'change color
                'Color Black
                Dim oColor As Color = Layer.Color
                oColor.Red = 0
                oColor.Green = 0
                oColor.Blue = 0
                Layer.Color = oColor
            'End If
        Next			
				
ThisDrawing.Document.StylesManager.Layers(“company logo1").Color = 
ThisApplication.TransientObjects.CreateColor(0, 0, 255) ' blue  <-- inserisci colore
ThisDrawing.Document.StylesManager.Layers("company logo2").Color = 
ThisApplication.TransientObjects.CreateColor(255, 127, 0) ' orange ' by Leocata Luca '<-- inserisci colore

If TypeOf oDocument Is DrawingDocument Then
'oOptions.Value("Publish_Mode") = pdfPublishModeEnum.kCustompdfPublish
oOptions.Value("Publish_All_Sheets") = 1
 End If
End If

oDataMedium.FileName = path_and_name & "_2D.pdf"
Call pdfAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
If launchviewer = 1 Then ThisDoc.Launch(path_and_name & "_2D.pdf")

'''--xx—restor original color --- ripristina colori

 

0 Likes
1,043 Views
5 Replies
Replies (5)
Message 2 of 6

R.Mabery
Advocate
Advocate

What part is giving you issues?

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 3 of 6

omvcilindri
Contributor
Contributor

I report the error indicated by the inventor and all the layers remain black, I would like to return them as before the export

 

 in System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   in Inventor.LayersEnumerator.get_Item(Object Index)
   in ThisRule.Main()
   in Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   in iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
0 Likes
Message 4 of 6

robertast
Collaborator
Collaborator
Message 5 of 6

R.Mabery
Advocate
Advocate

@omvcilindri I'm storing the Layer name, and the RGB values.  After export, I'm restoring those values.

 

There's no check to ensure that your company logo 1 and company logo 2 layers exist so you should check and create them if needed with your code.

 

‘esporta PDF in bianco e nero ma logo acolori

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

Dim oLayers As LayersEnumerator = oDrawDoc.StylesManager.Layers
Dim oLayer As Layer

Dim oModifiedLayers as New ArrayList

path_and_name = ThisDoc.PathAndFileName(False)
pdfAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

i = MessageBox.Show("Launch the viewer now?", "Title",MessageBoxButtons.YesNo)
If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If 

If pdfAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
	'oOptions.Value("All_Color_AS_Black") = 1
	oOptions.Value("Launch_Viewer") = launchviewer
	oOptions.Value("Publish_All_Component_Props") = 1
	oOptions.Value("Publish_All_Physical_Props") = 1
	oOptions.Value("Password") = 0
	oOptions.Value("Publish_All_Sheets") = 1
	'oOptions.Value("Publish_Mode") = pdfPublishModeEnum.kCustompdfPublish

	'loop through oLayers
	For Each oLayer In oLayers
		'assumption If DWG is in the name then alway the first 3 letters!
		Dim layerName As String = oLayer.Name
		Dim first3Letters As String = Strings.Left(layerName, 3)
		
		If first3Letters = "DWG" Then
			' Store name and RGB Value of Layer
			oModifiedLayers.Add(String.Concat(layerName,"@",oLayer.Color.Red,"@",oLayer.Color.Green,"@",oLayer.Color.Blue))
			
			'change color
			'Color Black
			Dim oColor As Color = oLayer.Color
			oColor.Red = 0
			oColor.Green = 0
			oColor.Blue = 0
			oLayer.Color = oColor
		End If
	Next			

	oLayers("company logo1").Color = ThisApplication.TransientObjects.CreateColor(0, 0, 255) ' blue  <-- inserisci colore
	oLayers("company logo2").Color = ThisApplication.TransientObjects.CreateColor(255, 127, 0) ' orange ' by Leocata Luca '<-- inserisci colore
End If

oDataMedium.FileName = path_and_name & "_2D.pdf"
Trace.WriteLine("iLogic: oDataMedium.FileName " & oDataMedium.FileName)

Call pdfAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

If launchviewer = 1 Then ThisDoc.Launch(path_and_name & "_2D.pdf")

'''--xx—restor original color --- ripristina colori

' Restore colors 
For each modlayerstring as String in oModifiedLayers
	Trace.WriteLine("iLogic: modlayerstring " & modlayerstring)
	
	Dim modlayer As String() = modlayerstring.Split(New Char() {"@"c})
	modlayerName = modlayer(0)
	modlayerRed = modlayer(1)
	modlayerGreen = modlayer(2)
	modlayerBlue = modlayer(3)
	
	oLayers.Item(modlayerName).Color.Red = modlayerRed
	oLayers.Item(modlayerName).Color.Green = modlayerGreen
	oLayers.Item(modlayerName).Color.Blue = modlayerBlue
Next

Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Here's another way.

Haven't tested it yet, after customizing it to your situation, though.

It uses a list of NameValueMaps.  NameValueMaps are perfect for storing a list of settings that each have a name and value.

Also I noticed you were accessing the DWF translator, instead of the PDF translator, so I'm showing a different (readable) way to set the Translator Addin, so you know what your getting.

And I also included all the other possible options you can access using the PDF translator addin.

See if this works for you.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oLayers As LayersEnumerator = oDDoc.StylesManager.Layers
Dim oLayer As Layer
Dim oLayerSettings As List(Of NameValueMap)
Dim oMap As NameValueMap
For Each oLayer In oLayers
	oMap.Clear : oMap.Add("Name",oLayer.Name) : 	oMap.Add("Blue", oLayer.Color.Blue)
	oMap.Add("Green", oLayer.Color.Green) : 	oMap.Add("Red", oLayer.Color.Red)
	oLayerSettings.Add(oMap)
	oMap.Clear
	If oLayer.Name = "company logo1" Then
		With oLayer.Color
			.Red = 0 : .Green = 0 : .Blue = 255
		End With
	ElseIf oLayer.Name <> "company logo2" Then
		With oLayer.Color
			.Red = 255 : .Green = 127 : .Blue = 0
		End With
	Else
		With oLayer.Color
			.Red = 0 : .Green = 0 : .Blue = 0
		End With
	End If
Next

Dim oPName As String = Left(oDDoc.FullFileName,Len(oDDoc.FullFileName)-4) & ".pdf"
Dim oPDFAddin As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAddin.DisplayName = "Translator: PDF" Then
		oPDFAddin = oAddin
	End If
Next

Dim oTransObjs As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTransObjs.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTransObjs.CreateNameValueMap
Dim oDataMedium As DataMedium = oTransObjs.CreateDataMedium
oDataMedium.FileName = oPName

oAns = MsgBox("Launch Viewer?", vbYesNo + vbQuestion, "PDF Viewer")
If oAns = vbYes Then oLaunch = 1 Else oLaunch = 0

'The following If-Then statement defines the Options available, and their Values.
If oPDFAddin.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
	oOptions.Value("Publish_All_Sheets") = 1 ' 0 = False, 1 = True
	oOptions.Value("Launch_Viewer") = oLaunch  ' 0 = False, 1 = True
	oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
	oOptions.Value("Publish_Mass_Props") = 1
'	oOptions.Value("Publish_Mode") = 62721 'This seems to be the norm for exporting a normal drawing. There may be another value for 3D PDF's.
	'oOptions.Value("Enable_Measure") = 1
	'oOptions.Value("Enable_Markups") = 1
	'oOptions.Value("Output_Path") = 
	'oOptions.Value("Sheet_Metal_Flat_Pattern") = 0
	'oOptions.Value("Sheet_Metal_Part") = 1
	'oOptions.Value("Weldment_Symbol") = 0
	'oOptions.Value("BOM_Parts_Only") = 1
	'oOptions.Value("Instructions") = 0
	'oOptions.Value("iAssembly_3D_Models") = 0
	'oOptions.Value("iPart_3D_Models") = 0
	'oOptions.Value("Publish_Screenshot") = 0
	'oOptions.Value("Facet_Quality") = 69379
	'oOptions.Value("Facet_Recompute_Tolerance") = 0.001
	'oOptions.Value("Sheet_Color") = 0
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 4   (it is not confirmed that this line works)
'	oOptions.Value("Vector_Resolution") = 4800 ' DPI
'	oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
	'oOptions.Value("Print_Excluded_Sheets") = 0 ' 0 = False, 1 = True (DOESN'T SEEM TO BE WORKING YET)
End If

'Check to see if the PDF already exists, if it does, ask if you want to over write existing or not.
If System.IO.File.Exists(oDataMedium.FileName) = True Then
	oAnswer = MsgBox("A PDF file with this name already exists." & vbCrLf &
	"Do you want to over write it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
	If oAnswer = vbNo Then 	Return
End If
'Publish PDF
oPDFAddin.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)

For i = 1 To oLayers.Count
	For Each oMap In oLayerSettings
		oLayers.Item(oMap.Value("Name")).Color.SetColor(oMap.Value("Red"), oMap.Value("Green"), oMap.Value("Blue"))
	Next
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)