Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Replace Custom Content Center Part With Standard Part

9 REPLIES 9
Reply
Message 1 of 10
Matthew_Policelli
692 Views, 9 Replies

Replace Custom Content Center Part With Standard Part

When our organization started using content center, there was a while it wasn't used correctly and so every part was a custom content center part when most of them could be standard. What I am trying to do is write an iLogic to clean up any remaining assemblies with custom parts that don't need to be custom. I've gotten all the code for determining when to replace custom with standard, but what I can't figure out is how to change the custom part to standard without having to write a lot of family-dependent code to get inputs and content center folder/family. Is there an easy way to just replace custom with standard?

9 REPLIES 9
Message 2 of 10

Here is a post dealing with replacing CC parts. The tricky part for you is determine the member that you have and to replace that. Maybe it will be of assistance to you. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 10

Sorry for the late response...

 

I think I have changing custom to standard pretty well figured out now. What I am looking for is an effective way to determine WHEN to change custom to standard. Is there a way to count the features in a custom part and compare that to the number of features in the standard part, without hard coding the number of features that the standard part should have for each family?

Message 4 of 10
jjstr8
in reply to: Matthew_Policelli

A good first pass might be to check the FileSaveCounter property.  Since CC does an initial save on placement whether or not it's Standard or Custom, the FileSaveCounter for a Custom CC component should be 1 if nobody made changes.  Saving a file when nothing changed doesn't seem to increment FileSaveCounter.

Message 5 of 10

Here is another post that might give you more insight to standard cc parts. What @jjstr8 suggest the FileSaveCounter

might be a good place to try.

 

FileSaveCounter Forum post and Help file. You can probably also check old member feature count and then check new member count. Although this logic will fall down if a feature was modified rather than added /deleted. You can also check the mass. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 10

Feature count seems to be the answer here IMO. But is there a way to get the feature count of the standard part (or the content family template part even) if there are no other standard parts in the same family in the assembly?

 

Or will I have to brute force it - change the part to standard, check the feature count, and replace it with the custom part again if they don't have the same feature count?

Message 7 of 10

Hi @Matthew_Policelli 

You will need to create the standard part on disk and then you can check the document for feature count. You don't need to replace it untill it matches your criteria. 

Here is a handy post that gets the content center family from a part. You would need to test if a custom content part is still recognized by this method.

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCC As ContentCenter = ThisApplication.ContentCenter
Dim oCCmember As ComponentOccurrence = oDef.Occurrences.ItemByName("KCKR 25 x 2 - 100:1")

Dim propSet As PropertySet = oCCmember.Definition.Document.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")

' Get FamilyId property
Dim familyId As Inventor.Property = propSet.Item("FamilyId")

'Get Family
Dim oContentFamily As ContentFamily = oCC.GetContentObject("v3#" & familyId.Value & "#") 
MeesageBox.Show(oContentFamily.DisplayName)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 8 of 10
jjstr8
in reply to: Matthew_Policelli

@Matthew_Policelli :  What did you see as the downside to the FileSaveCounter?  It seems like feature count would have no way of accounting for changes to an original feature, only if features were added.

Message 9 of 10
Matthew_Policelli
in reply to: jjstr8

Our custom parts that need to be changed to standard should always have a feature added instead of the original part being changed. That's because the ones I am targeting are wood parts, paneling parts, etc. If it has a miter or other cutouts, it needs to stay custom. But if it was just put in as custom because nobody at my company knew how to use standard parts until a few years ago, it should go back to standard.

 

So feature count should be 99.9% foolproof for our usage.

 

The problem I had with save counter is that in testing, I found standard parts from the same family with different FileSaveCounter values for some reason. I also had custom parts that had added features that had the same FileSaveCounter value as the standard part.

 

Because the parts in question also do not have conditional features as standard parts, how I've ended up doing my check is I determine if the part is a custom content center part, and then I place a temporary member of the family, check whether the number of features matches the part being tested, and then delete the temporary part. Here's a test version of my code for those who may be interested:

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return

	'Let user pick a part occurrence from the assembly
	Dim oCCmember As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select a component, press esc when complete")

	'Get document for the part the user picked
	Dim oPartDoc As Document = oCCmember.Definition.Document

	Logger.Info("Custom and can be changed to Standard? = " & IsCustom_CanBeStandard(oPartDoc))

End Sub

''' <summary>
''' Determine whether the part is a custom content center part that can be changed to standard.
''' </summary>
''' <param name="PartDoc">The part document being checked</param>
''' <returns>True if the part in question can be changed from custom to standard</returns>
Private Function IsCustom_CanBeStandard(ByVal PartDoc As PartDocument) As Boolean

	If Not (PartDoc.PropertySets.PropertySetExists("ContentCenter") AndAlso PartDoc.PropertySets("ContentCenter").Item("IsCustomPart").Value = "1") Then
		Return False	'return false if part is either not content center or is standard part
	End If

	'continue if it is a custom content center part...

	'get part content family object	
	Dim cf As ContentFamily = ThisApplication.ContentCenter.GetContentObject("v3#" & PartDoc.PropertySets("Content Library Component Properties").Item("FamilyId").Value & "#")


	Dim ee As MemberManagerErrorsEnum
	Dim featureCheck As Boolean

	Try
		ThisApplication.ScreenUpdating = False

		'create and place a standard part of the same family as the part in question
		Dim testOcc As ComponentOccurrence = CType(ThisDoc.Document, AssemblyDocument).ComponentDefinition.Occurrences.Add(cf.CreateMember(1, ee, "Problem"), ThisApplication.TransientGeometry.CreateMatrix())

		featureCheck = testOcc.Definition.Document.ComponentDefinition.Features.Count = PartDoc.ComponentDefinition.Features.Count	'true if picked part features match the standard part

		testOcc.Delete2(True)	'delete the test item without saving

	Catch ex As Exception
		Logger.Info("Error Trying to Check Standard Part Feature Count: " & ex.Message)
		Return False	'there was some kind of error so don't change the part
	Finally
		ThisApplication.ScreenUpdating = True
	End Try

	Return featureCheck
End Function
Message 10 of 10
jjstr8
in reply to: Matthew_Policelli

Gotcha.  I would assume an "untouched" custom part with the file save counter greater than one is just where someone poked around in the part enough to require a save, but didn't make a real change.  I think the file save counter would still help you avoid the temporary member and feature check.  It it's a custom part with the file save counter equal to one, you know for certain it can be replaced with the standard part. 

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

Post to forums  

Autodesk Design & Make Report