Assign color to all A-Side faces

Assign color to all A-Side faces

Zackery.Breeland
Contributor Contributor
1,200 Views
2 Replies
Message 1 of 3

Assign color to all A-Side faces

Zackery.Breeland
Contributor
Contributor

Hello all,

 

I have been working on this little task for a few days now and all of the searching through the forums has lead me nowhere.  I am trying to use the Pick command to select and define the A-Side of sheet metal components and then automatically change the A-Side color to a pre-selected color based on the sheet metal defaults.  I know how to select and define the A-Side and how to recall the sheet metal default names to set the color.  What I cannot figure out is how to make all the A-Side faces change color.

 

I have found things on how to change a single face with a specific name to a color, or change random colors of the whole part, but nothing for the A-Side.  I found a post where someone used Main and Sub routines to change the color of the A-Side (Solved: Ilogic Script for Highlight Defind A-Side and set the appearance ? - Autodesk Community - In...) , but I don't know how to work with routines like that and so I cannot edit it to change the color based on the sheet metal default.

 

Sub Main
Dim oDoc As PartDocument = ThisDoc.Document
Dim oSMDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
Dim oFace As Face

If oSMDef.HasFlatPattern Then
	'Skip entire rule, part is complete
	Else
		'Force User to select A-Side Face
		oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a feature")
		If Not oFace Is Nothing Then
			Call oSMDef.ASideDefinitions.Add(oFace)
		End If

		If oSMDef.ActiveSheetMetalStyle.Name.Contains("Tread") Then
			ChangeColor(oFace, "Red", oDoc) 'This is where I was attempting to use the sub routines I found
				
			End If
		End If
End Sub
	

 

My ultimate goal is to automate my sheet metal creation to avoid errors from others.  The rule will run upon save, check if there is a flat pattern, force a designated A-Side, Detect the sheet metal style used, Change the color of the A-side, then create the flat pattern.

0 Likes
Accepted solutions (1)
1,201 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @Zackery.Breeland.  Just some words of advise to start.  If you are not comfortable with using custom Sub routines or Function routines, you can usually just move the code from within the Sub routine over into the appropriate location within your main code (insert that code in the same place where you are calling it to run.  Then you may just need to fix any variable names being used by the Sub routine portion of the code to match any of the pre-existing variables you were using within your original code up to that point, if they are supposed to be representing the same objects.

 

Also, if you intend to have your code run every time you save the document, the situation may arise where you have already defined the A-Side face and/or set its color.  So, it might be wise to check if an 'ASideDefinition' has already been created, before initiating the 'Pick' method, then if one already exists, maybe exit the rule, or something like that.  Just a thought.

Just in case you were not aware, or did not realize, if using code similar to the example in the link you posted, there needs to already be an appearance asset within the 'Autodesk Appearance Library' with the same name as the color you are specifying for it to apply to the face.  If you have not already created those appearances, or they are not standard ones that already exist, you may want to create the ones you want before implementing your code.  Then if you plan to use this code on multiple documents, you will likely want to make sure you have saved any appearances you have created out to the library, so that they don't only exist within the document.  Or you could source them from another appearance library, like a custom one that you have created, as long as it is available to the document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

Zackery.Breeland
Contributor
Contributor
Accepted solution

Thank you for the advice.  I had tried taking the code out of the subroutines and pasting it in without the added if-then statements and kept getting an error.  Something you said about issues with running on save triggered a thought for me.  Due to the nature of rework and design changes I starting looking back over the options for triggers and realized I should break this single code up into 2, with the separate goals of 1) proper A-side definition and flat pattern creation and 2) proper color coding per sheet metal definition.  This allows for the first initial save to create the A-side and flat pattern so the overall orientation will be correct.  Then the second rule will trigger as well to set the proper color, but on future saves, only rule 2 will take effect and update the colors to any changes in design.  For now, this looks like it's going to work for my purposes.  Below are the two rules:

Rule 1 - A-Side Flat Pattern Creation

Dim oDoc As PartDocument = ThisDoc.Document
Dim oSMDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
Dim oFace As Face

If oSMDef.Features.Count > 0 Then
	If oSMDef.HasFlatPattern Then
		'Do nothing, Rule has been run
		Else oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a feature")
			If Not oFace Is Nothing Then 
	    		Call oSMDef.ASideDefinitions.Add(oFace)
			End If
			oSMDef.Unfold2(oFace)
	End If
End If

 

 Rule 2 - A-Side Color

Sub Main
	Dim oDoc As PartDocument = ThisDoc.Document
	Dim oSMDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition

	If (oSMDef.HasFlatPattern) Then
		Dim flat = oSMDef.FlatPattern
		Dim foldedFace = flat.ASideFace.ASideFace
		If (foldedFace IsNot Nothing) Then
			If oSMDef.ActiveSheetMetalStyle.Name.Contains("Tread") Then
				For Each faceX As Face In flat.ASideFace.Faces
					SetFaceColor(faceX, "Red", oDoc)
				Next
			Else
				booleanParam = InputRadioBox("Interior piece or Standard cutout?", "Interior Piece", "Standard Cutout", booleanParam, Title := "Title")
					For Each faceX As Face In flat.ASideFace.Faces
						If booleanParam = True
						SetFaceColor(faceX, "Etched", oDoc)
						Else
						SetFaceColor(faceX, "Satin", oDoc)
						End If
					Next
			End If
		End If
	End If
End Sub

Sub SetFaceColor(face As Face, appearanceName As String, partDoc As PartDocument)
	Dim asset As Asset = Nothing
	Try
		asset = partDoc.Assets.Item(appearanceName)
	Catch
		Dim assetLib = ThisApplication.AssetLibraries.Item("314DE259-5443-4621-BFBD-1730C6CC9AE9")  '("Autodesk Appearance Library")
		asset = assetLib.AppearanceAssets.Item(appearanceName)
		asset = asset.CopyTo(partDoc)
	End Try
	'Logger.Info("Asset name = {0}", asset.DisplayName)
	face.Appearance = asset
End Sub
0 Likes