Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to save color and lineweight of layer and recover it?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
kevinNSZML
198 Views, 2 Replies

How to save color and lineweight of layer and recover it?

Hi all,

 

As company policy, I need to help users export drawing as JPG for another department. However, when I test printing JPG file, all red, green, and blue line looks light gray color. Since there is no function like as "PrintAllColorsAsBlack" before I use "SaveAsJPG". I found a way to solve it that was change all layers to black and lineweight bigger. It seems good.

 

But, I want to recover all layer colors and lineweights back after saving JPG. So, I tried to use array to save all layer colors at the beginning, and write it back at the end. However, I failed many times. Although I can just discard saving, someone may save it accidentally. So, I want to avoid this mistake in advance. I am just a beginner of using iLogic. Is there anyone can help me about this request? I need help for part1 and part4 in the following?

 

Thanks so much.

 

[Workflow]

Part1: Save the beginning layer color

Part2: Change all layers color to black and lineweight=0.25

Part3: Save to JPG 

Part4: Recover the beginning color of layers

 

Sub Main

Dim drawdoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oLayers As LayersEnumerator
oLayers = drawdoc.StylesManager.Layers


'Part1: Save all current color of layers
'NEED HELP
'
'
'

'Part2: Make all layers color black
Dim oColor As Color
oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 0)
Dim oLayer As Layer
For Each oLayer In oLayers
	'oLayer.Color = oColor
	oLayer.LineWeight = 0.25
Next

'Part3: Save to JPG
oSheetName = ActiveSheet.Name
oSheetName = oSheetName.Replace(":","_P")
oPartnumber = iProperties.Value("Project", "Part Number")
oF_Path = "P:\JPG\" & DateString & "\" & oPartnumber & "(" & oSheetName & ")"
SaveAsJPG(oF_Path & ".jpg", 3000)

'Part4: Recover the beginning color of layers
'NEED HELP
'
'
'
End Sub

Public Sub SaveAsJPG(oPath As String, oWidth As Integer) Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet = oDoc.ActiveSheet Dim oView As Inventor.View = ThisApplication.ActiveView Dim dAspectRatio As Double = oSheet.Height / oSheet.Width ' Adjust the aspect ratio of the view to match that of the sheet oView.Height = oView.Width * dAspectRatio Dim oCamera As Camera = oView.Camera ' Center the sheet to the view oCamera.Fit ' Zoom to fit the sheet exactly within the view ' Add some tolerance to make sure the sheet borders are contained oCamera.SetExtents(oSheet.Width * 1.003, oSheet.Height * 1.003) ' Apply changes to the camera oCamera.Apply ' Save view to jpg. Make sure that the aspect ratio is maintained when exporting oView.SaveAsBitmap(oPath, oWidth, oWidth * dAspectRatio) ' Restore the view oCamera.Fit oCamera.Apply oView.WindowState = kMaximize End Sub

 

 

 

Labels (3)
2 REPLIES 2
Message 2 of 3
A.Acheson
in reply to: kevinNSZML

Hi @kevinNSZML 

For this you could use a dictionary to save the layer name and line weight, do the same for colour. See Microsoft help file for dictionary

 

However I would suggest to have a look at how you would do this manually in inventor through defining styles and standards. It would be much easier to control a predefined style rather than performing custom changes in each drawing. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3
WCrihfield
in reply to: kevinNSZML

Hi @kevinNSZML.  I thought about the Dictionary angle the other day, when you first posted this, but that would require a lot of processing, twice (once to record all those settings, then again to restore all those settings.  Another thought came to mind that might work better.  What about using a Transaction?  Those record certain kinds of things that you do in Inventor into items listed under your UNDO button.  You could save your drawing just before running this routine, then start a new Transaction just before making the layer changes, then export your image, then abort the Transaction.  Aborting the transaction is like clicking this action in the UNDO list.  It should undo the layer changes, but not undo exporting the image, because that was already written out to an external file.  However, once you start a transaction, if any errors stop the rule before it reaches the Transaction.Abort line, it will leave a potentially long list of stuff in your UNDO list that may need to be undone manually (if possible).  So, anywhere within the area of code after the transaction has been started, if a line of code might possibly fail (throw an error), you should probably envelop that line within the Try side of a Try...Catch block of code, to avoid those potential errors.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report