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: 

Make component pattern element independent and replace

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Koekepeerke
586 Views, 5 Replies

Make component pattern element independent and replace

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

5 REPLIES 5
Message 2 of 6
theo.bot
in reply to: Koekepeerke

@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 😉

Message 3 of 6
Koekepeerke
in reply to: Koekepeerke

@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!

Message 4 of 6
Koekepeerke
in reply to: theo.bot

@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!

Message 5 of 6
Koekepeerke
in reply to: Koekepeerke

i managed to solve the problem using:
If oComp.Name.contains("consistent part of component name") Then
oComp.Delete
Message 6 of 6
theo.bot
in reply to: Koekepeerke

Nice! glad you solved it 🙂

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

Post to forums  

Autodesk Design & Make Report