Defining A-Side for sheet metal part using Entitys

Defining A-Side for sheet metal part using Entitys

ashSPTSS
Participant Participant
179 Views
4 Replies
Message 1 of 5

Defining A-Side for sheet metal part using Entitys

ashSPTSS
Participant
Participant

Hi 

I were wondering if anyone know if it is possible to use iLogic to change which side is the A-Side.

I have named the 2 faces that i have the posibilities of using as my a side using the "Assign Entity Name" feature and would like to be able to change between the 2 sides being the A-side determined by a Variable called Orientation. My problem is that i can only find code that allows me to click manually on the side i want as the A-side.

My thoughts on the start code would be something like this. 

Dim partDoc As PartDocument = ThisDoc.Document
Dim compDef As SheetMetalComponentDefinition = partDoc.ComponentDefinition

If (compDef.HasFlatPattern) Then
	compDef.FlatPattern.Delete
End If

If Orientation = "RD"
	'compDef.ASideDefinitions.Add(RD Back) '<-- Not Working
Else If Orientation = "LG"
	'compDef.ASideDefinitions.Add(LG Back) '<-- Not Working
End If

 

ashSPTSS_0-1754654182781.png

ashSPTSS_1-1754654194332.png

 

Thanks in advance

 

Best regards 

Anders S Hammeken

 

 

Best regards
Anders S Hammeken
0 Likes
Accepted solutions (1)
180 Views
4 Replies
Replies (4)
Message 2 of 5

mat_hijs
Collaborator
Collaborator
Accepted solution

You can try this code. I'm pretty sure you can't edit the A-side definition after a flat pattern has been made so this code deletes the flat pattern if it exists and recreates it after editing the A-side definition.

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPartCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition

Dim bHasFlatPattern As Boolean = oPartCompDef.HasFlatPattern
If bHasFlatPattern = True Then oPartCompDef.FlatPattern.Delete

Dim oASideDefinitions As ASideDefinitions = oPartCompDef.ASideDefinitions

If oASideDefinitions.Count <> 0 Then
	For i As Integer = 1 To oASideDefinitions.Count
		oASideDefinitions.Item(i).Delete
	Next
End If

Dim sNamedEntityName As String = A_Side
Dim oFace As Face = ThisDoc.NamedEntities.TryGetEntity(sNamedEntityName)

If oFace IsNot Nothing Then oASideDefinitions.Add(oFace)

If bHasFlatPattern = True Then oPartCompDef.Unfold

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @ashSPTSS.  The ASideDefinitions object represents not only a collection of ASideDefinition objects, but provides properties to access the ones in the collection, and a method for adding more to the collection, so by its very nature, there can be multiple ASideDefinition objects in that one sheet metal part.  However, there does not appear to be a way to 'change' an existing ASideDefinition from using one Face to using another Face.  We can only add additional ones, access ones already in it (without the ability to changing them), or delete them.

So, is your design intent to only run this rule once on the document, or for it to potentially get ran multiple times on the same document?  Is your intent just to add one ASideDefinition, or both?  If your intention is for this rule to only add one (not both), then for it to switch between the two when the value of that parameter changes, then your code would need to first delete any already existing ASideDefinition(s), then add the one you want to use as a second step.  Once we know what your plan is, we may be able to help more effectively.

 

By the way, if you want to find / get a Face (or Edge or Vertex) that you assigned a name to using the built-in 'Assign Name' tool, within an iLogic rule, then there is two main routes of doing that.

This is an example showing one of the simpler routes, starting with the 'ThisDoc' iLogic 'RuleObject'.

Dim oMyNamedEntity = ThisDoc.NamedEntities.TryGetEntities("entity name")

 The other way, with more flexibility, is like the following:

Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
Dim oMyNamedEntity = oNEs.TryGetEntity("entity name")

...where the 'oDoc' variable would be replaced by whatever variable already represents the Inventor.Document object that you want to retrieve the named entities from, and "entity name" would be edited to the name you assigned to the entity.  Both of those example lines of code are using the newer 'TryGetEntities' method, which will not throw an error if it can not find an entity by the specified name, but will instead just not return a value to assign to the variable.  There is also the method named 'FindEntity', which is older, and will throw an error if it can not find an entity with the specified name.

Plus, when you include the unquoted name of a Parameter within an internal iLogic rule, it usually turns Blue (by default), which means it is recognized as representing a Parameter, and its presence in that rule will cause that rule to get automatically ran every time the value of that parameter changes.  That behavior can be turned off, but that is the default behavior, just in case you were not already aware.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

ashSPTSS
Participant
Participant

Hi Wesley

 

Thanks for your input. The idea was for the part to be able to change the one A-side from one face to another when the variable changes. This should be able to run more than one time. with a little twerk of nat_hijs code it seems posible.

Best regards
Anders S Hammeken
0 Likes
Message 5 of 5

ashSPTSS
Participant
Participant

@mat_hijs thanks with a little twerk it looks like it worked

 

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPartCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition

Dim bHasFlatPattern As Boolean = oPartCompDef.HasFlatPattern
If bHasFlatPattern = True Then oPartCompDef.FlatPattern.Delete

Dim oASideDefinitions As ASideDefinitions = oPartCompDef.ASideDefinitions

If oASideDefinitions.Count <> 0 Then
	For i As Integer = 1 To oASideDefinitions.Count
		oASideDefinitions.Item(i).Delete
	Next
End If
Dim A_Side
If Orientation = "RD"
	A_Side = "RD_Back"
Else 
	A_Side = "LG_Back"
End If


Dim sNamedEntityName As String = A_Side
Dim oFace As Face = ThisDoc.NamedEntities.TryGetEntity(sNamedEntityName)

If oFace IsNot Nothing Then oASideDefinitions.Add(oFace)

If bHasFlatPattern = True Then oPartCompDef.Unfold
Best regards
Anders S Hammeken
0 Likes