Make component pattern element independent and replace

Koekepeerke
Advocate
Advocate

Make component pattern element independent and replace

Koekepeerke
Advocate
Advocate

in an assembly i have a pattern wich consists of a series of profiles i want to be able to easily replace a single pattern element with a different variety of profile. the way i have it build now is that the other variety of profile is always in the assembly but the visibility is turned off then i use a parameter to specify the element that has to be 'replaced' but all i do is supress de element en switch the visibility of the other profile. here a simplified version of the code i'm using right now:

AddVbFile "NXTdimConnector.iLogicVb"
'Try to make connection with NXTdim
Dim NXTdim As Object = NXTdimConnector.GetNXTdimiLogicAutomation(ThisApplication)
If NXTdim Is Nothing Then 
	MessageBox.Show("Could not connect to the NXTdim Inventor iLogic extension library.", "NXTdim", MessageBoxButtons.OK, MessageBoxIcon.Stop)
	Exit Sub
End If

Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

'Dim oPattern As OccurrencePattern 

For Each oPattern In oDef.OccurrencePatterns

For Each oElement As OccurrencePatternElement In oPattern.OccurrencePatternElements
        If oElement.Suppressed = True Then
               oElement.Suppressed = False
        End If
Next
Next

	Dim oDoc As AssemblyDocument
	oDoc = ThisApplication.ActiveDocument

	'reference the pattern in the assembly 
	Dim oPattern As OccurrencePattern 
	'calls the pattern by name
	oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 10:1") 
	
	oPattern.OccurrencePatternElements.Item(parameter specifying element).Suppressed = True
	NXTdim.SetOccurrenceVisibilityByName(ThisDoc.Document, "different profile", True)

 even though this works for the application what i would really like to do is first make the element indepent and then replace it because this would be better for usage in different situations. now making the element independent is no problem but specifying the component to replace is where i'm stuck since the reference can change when it's a different element that needs replacing.

any help or advice would be greatly appreciated.

 

regards,

Jeremy

0 Likes
Reply
Accepted solutions (1)
602 Views
5 Replies
Replies (5)

theo.bot
Collaborator
Collaborator
Accepted solution

@Koekepeerke ,

 

Before you make a element independent, you can take the component(s) from that element. You can use this for the replace action after you made the element independent.

 

here is a sample, you need to adjust it to your needs:

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'reference the pattern in the assembly 
Dim oPattern As OccurrencePattern 
'calls the pattern by name
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("MyPattern") 

' get the component from the pattern element 2. In this case i simply take the first component, but depending on your model you should find yours if this contains more then one component.
Dim oComponent As ComponentOccurrence
oComponent = oPattern.OccurrencePatternElements.Item(2).Components.Item(1)

'Make pattern element 2 independent
oPattern.OccurrencePatternElements.Item(2).Independent = True
	
'replace component
oComponent.Replace("D:\01 Data\Workingfolder Vault\Designs\Projects\P900 - Support\Schijf.ipt",False)

 Succes, Doe je best 😉

Koekepeerke
Advocate
Advocate

@theo.bot 

Thanks alot for your reply Theo it works like a charm! i do have another question though. i need to 'refresh' the model before doing a new replacement. i do have this bit to refresh the pattern: 

For Each oPattern In oDef.OccurrencePatterns

For Each oElement As OccurrencePatternElement In oPattern.OccurrencePatternElements
        If oElement.Independent = True Then
               oElement.Independent = False
        End If
Next
Next

But when i want to replace an other element the previous replaced part stays in the model.

is there an easy way to delete the element from the previous action. since the name and location in the pattern will change everytime i don't know how to refer to the part. Perhaps by renaming the browser name after replacing and then deleting?

 

In ieder geval bedankt voor de hulp alvast!

0 Likes

Koekepeerke
Advocate
Advocate

@theo.bot 

Thanks alot for your reply Theo it works like a charm! i do have another question though. i need to 'refresh' the model before doing a new replacement. i do have this bit to refresh the pattern: 

For Each oPattern In oDef.OccurrencePatterns

For Each oElement As OccurrencePatternElement In oPattern.OccurrencePatternElements
        If oElement.Independent = True Then
               oElement.Independent = False
        End If
Next
Next

But when i want to replace an other element the previous replaced part stays in the model.

is there an easy way to delete the element from the previous action. since the name and location in the pattern will change everytime i don't know how to refer to the part. Perhaps by renaming the browser name after replacing and then deleting?

 

In ieder geval bedankt voor de hulp alvast!

0 Likes

Koekepeerke
Advocate
Advocate
i managed to solve the problem using:
If oComp.Name.contains("consistent part of component name") Then
oComp.Delete
0 Likes

theo.bot
Collaborator
Collaborator
Nice! glad you solved it 🙂
0 Likes