Delete parts in assembly based on parameters equalling to zero

Delete parts in assembly based on parameters equalling to zero

GKPByDesign
Advocate Advocate
973 Views
6 Replies
Message 1 of 7

Delete parts in assembly based on parameters equalling to zero

GKPByDesign
Advocate
Advocate

I want to run a code that will delete parts that have certain parameters that are equal to zero. 

 

Eg,

 

Scan for three parameters,

 

Length

Width

Thickness

 

If all three equal zero, surprises and or delete, (prefer delete) 

 

Can this be done? 

0 Likes
Accepted solutions (1)
974 Views
6 Replies
Replies (6)
Message 2 of 7

Sergio.D.Suárez
Mentor
Mentor

Hi, try the following ilogic rule. Execute it from the master assembly. You must have the parameters highlighted in red inside the files so that you can remove the component in the assembly, these parameters must be equal to zero.

 

Dim AssyDoc As AssemblyDocument = ThisDoc.Document
Dim oCD As AssemblyComponentDefinition = AssyDoc.ComponentDefinition
Dim oLength As Double, oWidth As Double, oThick As Double

For Each oCc As ComponentOccurrence In oCD.Occurrences
	Dim doc As Document = oCc.Definition.Document
	Try
		oLength = doc.ComponentDefinition.Parameters("Length").Value
		oWidth = doc.ComponentDefinition.Parameters("Width").Value
		oThick = doc.ComponentDefinition.Parameters("Thickness").Value
		If oLength = 0 And oWidth = 0 And oThick = 0 Then oCc.Delete
	Catch
	End Try
Next

 

I hope this helps with your problem. Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 7

GKPByDesign
Advocate
Advocate

Hello, it does not seem to work, I have had to remove the thickness parameter and othick, as I do not need these to be checked. But the file does not delete and it has the Length and Width para. 

 

Any suggestions? 

0 Likes
Message 4 of 7

GKPByDesign
Advocate
Advocate

I am unsure if the code is search the part file for these values, because it should be...

0 Likes
Message 5 of 7

Sergio.D.Suárez
Mentor
Mentor

I Take an assembly, choose a component from it, and set the user parameters that I have placed. I gave two parameters equal to zero and the third nonzero. Run the rule and I don't delete the component. Then I gave zero value to all three, run the rule and remove these components from the assembly.
You have to keep in mind that these components belong to this assembly, they are not components of an internal subassembly to this master assembly.
See if you can manually remove the component from the assembly you are working on.
On the other hand it would be easier to find a solution, if you shared an example assembly. The actual assembly is not necessary to avoid compromising design. A test assembly only to replicate the error.
Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 6 of 7

GKPByDesign
Advocate
Advocate

Hello, the assembly only contains part files.

 

Zip file attached, inside the assembly I have purposely added one file that suits the criteria to be deleted, but it is not working. 

0 Likes
Message 7 of 7

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

What happens is that values equal to zero are not internal user parameters of the part file. The values that you have equal to zero in your file are custom iproperties, in order to eliminate the component with the criteria you need you should have an ilogic rule like the following.

Dim AssyDoc As AssemblyDocument = ThisDoc.Document
Dim oCD As AssemblyComponentDefinition = AssyDoc.ComponentDefinition
Dim oLength As String, oWidth As String, oThick As String

For Each oCc As ComponentOccurrence In oCD.Occurrences
	Dim doc As Document = oCc.Definition.Document
	Try
		oLength = doc.PropertySets("Inventor User Defined Properties").Item("Length").Value
		oWidth = doc.PropertySets("Inventor User Defined Properties").Item("Width").Value
		oThick = doc.PropertySets("Inventor User Defined Properties").Item("Thickness").Value
		If oLength = "0 mm" And oWidth = "0 mm" And oThick = "0 mm" Then oCc.Delete
	Catch
	End Try
Next

 With this rule I have been able to remove from the assembly the component that has the three iproperties values at zero.
I hope this helps with your problem. Cheers


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn