Rename element in circular pattern

zoe.baker-bushby
Enthusiast

Rename element in circular pattern

zoe.baker-bushby
Enthusiast
Enthusiast

Hello,

I have a rule that edits a circular pattern, it goes in and selects certain occurrences and makes them independent. Works fine. Now I need a rule that undoes this. I have managed to get it to delete the new independent parts. Then make the parts dependent again. But now I have the issue of changing their names back. As the parts when returned to the pattern do not get their original occurrence number but instead start counting from the last occurrence (which is 14). The elements in this code go by the name of 'COURSE 01 STEEL TANK SHEET Alpha v1:.......' where the dotted line is the occurrence number. I've tried a range of code to change the name back and have generally gave up at his point. What is shown below is very basic and just demonstrates what doesn't work. The message box shows the attached photo, showing that it isn't even referencing the correct thing, I need it to reference the 'COURSE 01 STEEL TANK SHEET Alpha v1:.......' name not the element. So therefore the last line does not work. I have tried many ways, and reverted back to this simple code as to try and explain what I am wanting. Any help would be greatly appreciated.

(Also any help on cleaning up the previous parts would be appreciated, I new to this syntax of coding, plain ilogic is easy for me but this type of code is all pretty new) 

 

'Delete the independant parts
Dim doc As AssemblyDocument
doc = ThisDoc.Document

Dim oComp As ComponentOccurrence

Dim oComps As ComponentOccurrences
oComps = doc.ComponentDefinition.Occurrences

For Each oComp In oComps
If oComp.Name.Equals("COURSE 01 STEEL TANK SHEET Alpha v1:2") Or oComp.Name.Equals("COURSE 01 STEEL TANK SHEET Alpha v1:3") Or oComp.Name.Equals("COURSE 01 STEEL TANK SHEET Alpha v1:5") Or oComp.Name.Equals("COURSE 01 STEEL TANK SHEET Alpha v1:12")Then
oComp.Delete
End If
Next

'Make the parts dependent again
Dim oCompDef As PartComponentDefinition
oDoc = ThisDoc.Document
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("COURSE 01 STEEL TANK Sheet Pattern")
oPattern.OccurrencePatternElements.Item(2).Independent = False
oPattern.OccurrencePatternElements.Item(3).Independent = False
oPattern.OccurrencePatternElements.Item(5).Independent = False
oPattern.OccurrencePatternElements.Item(12).Independent = False

 

'Change their names back
MessageBox.Show(oPattern.OccurrencePatternElements.Item(2).Name )
oPattern.OccurrencePatternElements.Item(2).Name = "COURSE 01 STEEL TANK SHEET Alpha v1:2"

 

'Reset parameter
BespokeCount = 1

0 Likes
Reply
Accepted solutions (1)
882 Views
3 Replies
Replies (3)

WCrihfield
Mentor
Mentor

I guess I'm not understanding what you are trying to do here.

Why are you changing whether or not the pattern members are Independent of the pattern?

It looks like you're deleting the occurrences, then trying to make the deleted occurrences independent of their parent pattern, then trying to rename the deleted occurrences.

Are you deleting some occurrences, then trying to rename the remaining occurrences, with the same names as the ones you deleted? If so why?

Perhaps a different kind of search would be better.  How else are all of those specific occurrences special?

 

However, you should know that the OccurrencePatternElement.Name is a ReadOnly property, so it can't be changed, only read.

 

So, all I did was condense your code a bit, so far.

'Delete the independant parts
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oComps As ComponentOccurrences = oADef.Occurrences
Dim oComp As ComponentOccurrence

Dim oCName As String = "COURSE 01 STEEL TANK SHEET Alpha v1"
Dim oItemNum As Integer = 1

For Each oComp In oComps
'	If oComp.Name.Contains(oCName) And
'		something else unique about it is true or false or equals something Then
	If oComp.Name.Equals(oCName & ":2") Or _	
		oComp.Name.Equals(oCName & ":3") Or _
		oComp.Name.Equals(oCName & ":5") Or _
		oComp.Name.Equals(oCName & ":12") Then
		oComp.Delete
	End If
Next

'Make the parts dependent again
oPattern = oADef.OccurrencePatterns.Item("COURSE 01 STEEL TANK Sheet Pattern")
oPattern.OccurrencePatternElements.Item(2).Independent = False
oPattern.OccurrencePatternElements.Item(3).Independent = False
oPattern.OccurrencePatternElements.Item(5).Independent = False
oPattern.OccurrencePatternElements.Item(12).Independent = False

MessageBox.Show(oPattern.OccurrencePatternElements.Item(2).Name )

'Reset parameter
BespokeCount = 1

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

zoe.baker-bushby
Enthusiast
Enthusiast

Hi I'll try and explain it a little better: 

(You may notice that COURSE 01 STEEL TANK.... is now COURSE 1 STEEL TANK - had to remove the zero for other reasons)

I am trying to get a way to alter a pattern. So to start there is a circular pattern of the same standard sheet. Then I have a rule that identifies which sheets in this pattern need altering to a bespoke sheet. I have the following code that makes the standard sheet independent and then replaces it with the bespoke sheet part -- this works I have no issues, it does what I want. 

 

'Move bespoke sheet out of pattern by making it independent
oDoc = ThisDoc.Document
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("COURSE 1 STEEL TANK Sheet Pattern")
oPattern.OccurrencePatternElements.Item(BespokeSheet).Independent = True

'Replace this independent sheet with a bespoke sheet (counting through the bespoke sheets available) 
Component.Replace("COURSE 1 STEEL TANK SHEET Alpha v1:" & BespokeSheet, "BESPOKE TANK SHEET " & BespokeCount & " Alpha v1.ipt", False)

BespokeCount = BespokeCount + 1

iLogicVb.UpdateWhenDone = True

 

 

BUT then I need a way to undo this, reset everything. To do this manually, you have to delete the independent bespoke sheets. Then find the elements in the pattern which these came from, making them dependent again. Then rename.  So naturally this is the procedure that I am trying to code. I have managed to use your condensed code to delete the independent bespoke sheets. Then find the elements in the pattern which these came from and make them dependent again. But still the renaming issue stands. 

I understand that this may not be the best way about the whole of what I am trying to achieve but my first bit works so now I'm just trying to get the reset to work. It can be done manually so theoretically it should be able to be done with code... 

 

I have noticed that in the iProperties, Occurrence, Name is where the name that I am trying to alter is. Is there any way to reference the Occurrence Name iPropertie?? (See attached picture) As that is what I was previously trying to do but as you explained my code found the read only element number instead. 

 

If you have any suggestions I will be grateful. I hope I have explained the issue better and I thank you for the code you have provided, works fine.

 

 

0 Likes

zoe.baker-bushby
Enthusiast
Enthusiast
Accepted solution

I managed to achieve what I wanted with the help of: https://forums.autodesk.com/t5/inventor-forum/change-occurence-name-via-ilogic/m-p/9671771#M797733

 

Here is the code if anyone ever needs it for a similar problem:

'Delete the independant parts
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oComps As ComponentOccurrences = oADef.Occurrences
Dim oComp As ComponentOccurrence

Dim oCName As String = "COURSE 1 STEEL TANK SHEET"
Dim oItemNum As Integer = 1

For Each oComp In oComps
	If oComp.Name.Equals(oCName & ":2") Or _	
		oComp.Name.Equals(oCName & ":3") Or _
		oComp.Name.Equals(oCName & ":5") Or _
		oComp.Name.Equals(oCName & ":12") Then
		oComp.Delete
	End If
Next 

'Make the parts dependent again
oPattern = oADef.OccurrencePatterns.Item("COURSE 1 STEEL TANK Sheet Pattern")
oPattern.OccurrencePatternElements.Item(2).Independent = False
oPattern.OccurrencePatternElements.Item(3).Independent = False
oPattern.OccurrencePatternElements.Item(5).Independent = False
oPattern.OccurrencePatternElements.Item(12).Independent = False

'Rename parts in the sheet pattern
OccCounter = 0
For Each oComp In oComps
	GetOccName = oComp.Name
	OccCounter = OccCounter + 1
	Try
	If oComp.Name.Contains("COURSE 1 STEEL TANK SHEET") Then
		NewName = (GetOccName.Split(":")(0)) ' Removes ":1" from the Browser Node
		oComp.Name = NewName & ":" & OccCounter
	End If 
Catch : End Try : Next

'Reset parameter
BespokeCount = 1
0 Likes