Create Component with ilogic rule

Create Component with ilogic rule

MJefferyFTK52
Explorer Explorer
790 Views
6 Replies
Message 1 of 7

Create Component with ilogic rule

MJefferyFTK52
Explorer
Explorer

Hello, 

How can I populate the user inputs with preset variables of a Component Create command initiated with the command manager? Running the line below in an illogic rule skips the UI asking for template, file name, file location etc. and prompts the user for a surface. After picking a surface this command fails unless the create command is first used manually, then it will populate the prompts with the previous inputs. Is there any way to access these prompted inputs with an illogic rule to fill them out with data from the assembly automatically before prompting the user for the base sketch plane and adding to the assembly?

 

ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyCreateComponentCmd").Execute

 

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

A.Acheson
Mentor
Mentor

Hi @MJefferyFTK52 

I would suggest to do this work through the API. Using commands is really only for automating user interactions when no API exists. Does your component need to be created in the assembly exclusively? 

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

MJefferyFTK52
Explorer
Explorer

thank you for the reply. Yes, the component will be created exclusively in assemblies. The assembly is made up of a series of released parts placed and constrained with a rule based off user inputs. The goal with placing the created component was to use the same inputs to select the appropriate template and fille save location then prompt the user for the file name.

 

I have limited experience with Inventors API. Any suggestions or direction to resources on that front would be much apricated.          

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor
Accepted solution

Here is a random sample to create a part from part template. Your only really needing the first line shown below. You can specify a template filepath directly in place of the file manager fetching one. 

 

  ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject,ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

and here is the help page for all the arguments of the documents.add method.
Syntax

 

Documents.Add( DocumentType As DocumentTypeEnum, [TemplateFileName] As String, [CreateVisible] As Boolean ) As Document

Here is the help sample to place an occurrence. Written in VBA, so to convert to VB.Net for the ilogic environment. Remove the word Set and drawings call the sub routine from sub main. You can set this up as a separate rule and when you feel comfortable with how it works combine it with the part creation rule to place directly the part to the assembly in one rule. 

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

MJefferyFTK52
Explorer
Explorer

I was able to get a rule working with the method described. I do have one question though. What is the benefit of using the VBA method for placing a single occurrence linked in your previous response, as apposed to Components.Add()?

 

Thank you for your help! 

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor

Hi @MJefferyFTK52 

To clarify although I linked you to VBA samples I described the method to convert the launguage to VB.NET to work in the ilogic enviroment. I just added a better description above. 

 

Components.add help page here is using the ilogic API which is more user friendly. It uses short functions to gain access to objects. These functions actually have the inventor API code running behind them so it shields the user from more complicated code. However it will not give you access to more complex functionality like creating sketches, extruding sketches, creating workplanes, creating parts etc. 

You can actually use the ilogic API and the Inventor API wherever you need to and probably have been doing allready. 

 

So components.add can skip to this line in the Inventor API sample. So obviously shorter. 

 

Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)

 

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

JBerns
Advisor
Advisor

@MJefferyFTK52 and others who may have found this thread, this "create component in assembly" solution may be of interest:

 

https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-create-a-new-component-in-an-assem... 

 

Great solution by @JhoelForshav.

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional