Components.AddContentCenterPart

Components.AddContentCenterPart

florescu.d95
Enthusiast Enthusiast
341 Views
4 Replies
Message 1 of 5

Components.AddContentCenterPart

florescu.d95
Enthusiast
Enthusiast

Hi all,

 

This piece of code adds/updates  a standard content center part (Top plate) in my assembly.

If TopPlate_Bespoke= False Then 
Dim Top_plate = Components.AddContentCenterPart("Top plate",
                                                "Plates:Rack unit plates",
                                                "Top Plate",
                                                 {"Member", "Top Plate-" & Colour & "-" & Type & "-" & Depth & "x" & Type_Dim & " mm" })
End If 

 Sometimes I need to add the Top plate as Custom (TopPlate_Bespoke= True) and save it int the project folder with a different name in order to perform modifications to it.

How would this be done? I have seen that Components.AddCustomContentCenterPart exists but could't figure it out.

My goal is to achieve the same result as when manually placing a content center part as custom.  

@WCrihfield @NachoShaw, any clues?

0 Likes
342 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @florescu.d95.  I know you tagged me on this one, but I am most likely not the best one to reply on this one, because I honestly never use that iLogic snippet for adding a custom content center part to an assembly.  What I can do is point you to the online help page for that snippet, which might have better explanations than the Intellisense system tips offer while writing the code into an iLogic rule.

IManagedComponents.AddCustomContentCenterPart Method 

 

That method is asking for a lot of information, so you would most likely have to prepare some variables ahead of time in previous lines of code, and set the values for them before the line of code for that method.  There are also a couple input parameter types that are unique to the iLogic add-in (not available in Inventor's API), so that can sometimes be a little confusing.  For instance the input named "position" (ninth input) is a PointOrMatrix Interface.  It would seem like this is a compound Type, accepting either a DocumentUnitsMatrix type object, or a DocumentUnitsPoint type object, instead of a regular Matrix or Point object.  Then the other optional input named "appearance" (twelfth input) is a StringOrAsset Type.  That Type's description is even more complicated, but it would seem like you could supply either the name (String) of an Asset, or an actual Asset object there.  Assets are basically used to store the data for things like Material, Appearance, Physical Properties of a material.  They can be obtained from either an external AssetLibrary, or from a Document object that has local copies in it (the Material & Appearance specs being used or stored within documents).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

florescu.d95
Enthusiast
Enthusiast

@WCrihfield  Thanks for taking the time to reply. 

I was looking though the documentation yesterday night but I couldn't figure out a way to make it work. Today with a bit of fresh energy I have found a solution.

First, I've created a custom parameter in the family table just to give "customValues As Object()" something to change, it does not drive anything.

Here is the rest

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmName = oAsmDoc.DisplayName.Replace(".iam", "")
Dim oPath As String = ThisDoc.Path
Dim oFolderName As String ="Components"
Dim oFolder = oPath & "\" & oFolderName 
        If Not System.IO.Directory.Exists(oFolder) Then
            System.IO.Directory.CreateDirectory(oFolder)
        End If
If TopPlate_Bespoke = True Then
Dim
Top_plate = Components.AddCustomContentCenterPart("Top plate", "Plates:Rack unit plates", "Top Plate", {"Member", "Top Plate-" & Colour & "-" & Type & "-" & Depth & "x" & Type_Dim & " mm" }, {"Cparam", "1" }, asCustom := True, partFolder := oFolder, partFilename := "Top Plate" & "-" & oAsmName & ".ipt")
End If

 Hope it makes some sense 

0 Likes
Message 4 of 5

florescu.d95
Enthusiast
Enthusiast

Just noticed something with the code above.

Som  etimes it works and sometimes it throws this:

Error on line 29 in rule: Config rule 2, in document:  Unit assembly template.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Line 29 being :

Dim Top_plate = Components.AddCustomContentCenterPart("Top plate",

Then if i restart Inventor it works.

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Hi @florescu.d95.  That error basically means that it was not able to use one of the inputs you supplied into that AddCustomContentCenterPart method, for one reason or another.  The first possibility that come to mind is that there is already a component present in the assembly with that same exact name, and it will not allow two components to have exactly the same name.  That is why it always puts something like ":1" after the component name when they are added manually.  I believe that when adding components into an assembly by code, it lacks the user interaction required for the automatic rename utility catch and react to, so it does not rename stuff created that way.  Another theory is that a model file with the same path and name as that line of code generates may already exist, and it may not want to overwrite that existing file.  Or, perhaps the simple act of overwriting an existing file is not the problem, but maybe it will not allow you to overwrite the file if a reference to that file is currently being held in Inventor's session memory for some reason.  If that file was just created during your current session of Inventor, and maybe even while the same assembly was still open, then it is possible that a reference to that may still exist in Inventor's session memory.  If that is the case, then one other thing comes to mind that may be able to help.

ThisApplication.Documents.CloseAll(True)

The 'True' in that line specifies that it should only clear out all of the unreferenced documents being held in Inventor's session memory, and not to close any documents that are still being actively referenced by open assemblies or drawings.  This is a good tool to help performance when looping through many file/document references.  It is often used together with the Document.ReleaseReference method, which is used to get rid of references to documents that were opened invisibly (in the background), and are not being used by anything else.

Not sure if any of these may be the cause, or if any of these suggestions may help, but just throwing out some stuff that comes to mind, in case it may help.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes