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: 

Inserting a part and constraining to orgin using iLogic

19 REPLIES 19
Reply
Message 1 of 20
S7RM7RPR
874 Views, 19 Replies

Inserting a part and constraining to orgin using iLogic

I'm trying to find a way to insert a part, and ground/constrain it at the orgin using iLogic. Based on my searches, it seems the best way is to replace parts, but I'm trying to get around having upwards 300 parts replaced and/or pre-placed.

 

My idea is to have a self-replicating and self-placing part. The part would copy and paste itself as many times as needed, then the assembly would place those parts at the orgin and ground them, then update said parts with the required dimensions. The only part I'm missing, is how to insert, and ground a part automatically.

 

Also, said part would have 3 different variables that would make it the correct size and put it in the correct position.

19 REPLIES 19
Message 2 of 20
MechMachineMan
in reply to: S7RM7RPR

Why do you need to do this? What does it accomplish?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 20
S7RM7RPR
in reply to: MechMachineMan

This is a filler part for another series of parts that are automatic. The trick is I could potentially need up to 12 fillers for every main part, and every single filler could have a different size to fill the gap. Then I could have anywhere from 2 to 30 main parts, which ends up being up to 360 potential parts that are potentially unique. So the idea with this self-replicating self-placing filler, is that I reduce the number of files, and significantly reduce the amount of setup I have to do, otherwise I will need to pre-setup each filler piece..

 

Obviously this would also make this specific piece completly autonomus and I would never have to update it in case the quantity requirements change..

Message 4 of 20
MechMachineMan
in reply to: S7RM7RPR

Sounds like using parameters to resize parts might be an option?

Otherwise, you can use control definitions to accomplish the other parts

 

 

 

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager

Dim oControlDef1 As ControlDefinition

Dim oSelectSet As SelectSet
oSelectSet = oDwgDoc.SelectSet
oSelectSet.Clear
oSelectSet.Select(oS2)

oControlDef1 = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_GroundAndRootComponentCmd)
oControlDef1.Execute


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 5 of 20
S7RM7RPR
in reply to: MechMachineMan

I'm sorry I forgot to mention, I am not a programmer at all. I am completely making this up as I go so if you could explain that a little bit more it would be much appreciated.

The parameters isn't a problem, I'm not worried about that at all. The problem is that if I have to pre-setup all 360 potential parts, it's going to be days of work just setting that up, plus it will make my program run far slower because it will have to suppress or un-suppress the necessary parts. If however, I can have the parts insert and ground as needed, it would make the process far simpler.

Also, if there is a better way of doing this that I haven't figured out yet please feel free to mention it.
Message 6 of 20
MechMachineMan
in reply to: S7RM7RPR

You could always make all of your filler parts, by constantly doing a SaveAs then changing the file so they all have the same internal ID and coordinate system, and then just make a rule/replace the file as needed?

Or make a rule that changes the filler part to the proper size every time you open an assembly that contains it and just use one part file.

Or use an iPart.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 7 of 20
S7RM7RPR
in reply to: MechMachineMan

Correct me if I'm wrong, but the problem with all of those solutions is I still need to have all 360 parts available so that I can have them all in the assembly. I can copy the part as many times as I need, but I still need to place them in the assembly. I want to have them placed automatically as needed.
Message 8 of 20
S7RM7RPR
in reply to: S7RM7RPR

Just to make sure I'm clear on my request, all I'm looking for is a code that will allow me to insert and constrain parts to the origin. I've already created code that will self-replicate and update an infinite amount of parts, but now I need to be able to automatically insert those parts into an assembly
Message 9 of 20
MechMachineMan
in reply to: S7RM7RPR

Have you looked into the bonus assembly tools "Ground And Root Component" command?

It's found in an assembly, under the assembly tab, within the dropdown box that says "Productivity".

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 10 of 20
S7RM7RPR
in reply to: MechMachineMan

Well that would be the command I would use to add the parts manually, but I can't find any code for it to make it automatic
Message 11 of 20
MechMachineMan
in reply to: S7RM7RPR

The code I posted earlier is exactly what you need to mimic that command. The oS2 is what needs to be replaced with the object that defines the component. that you place in.

You would also need to write a code based on the different variables to select which part you are going to insert into the assembly in the first place.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 12 of 20
S7RM7RPR
in reply to: MechMachineMan

Oh, well to be fair I did ask you to explain that a little more. As I said, not a programmer so I really am making this up as I go.

Rule Compile Errors in Rule2, in Assembly2.iam

Error on Line 7 : 'oDwgDoc' is not declared. It may be inaccessible due to its protection level.
Error on Line 11 : String constants must end with a double quote.


Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef1 As ControlDefinition

Dim oSelectSet As SelectSet
oSelectSet = oDwgDoc.SelectSet
oSelectSet.Clear
oSelectSet.Select(ThisDoc.Path & "\cube\Cube1.ipt")

oControlDef1 = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_GroundAndRootComponentCmd)
oControlDef1.Execute
Message 13 of 20
MechMachineMan
in reply to: S7RM7RPR


@ajknexlang wrote:
Oh, well to be fair I did ask you to explain that a little more. As I said, not a programmer so I really am making this up as I go.

Rule Compile Errors in Rule2, in Assembly2.iam

Error on Line 7 : 'oDwgDoc' is not declared. It may be inaccessible due to its protection level.
Error on Line 11 : String constants must end with a double quote.

Dim oDoc As Document = ThisApplication.ActiveDocument' Add in the declaration and intialize the value
or
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef1 As ControlDefinition

Dim oSelectSet As SelectSet
oSelectSet = oDwgDoc.SelectSet ' New: oDoc.SelectSet
oSelectSet.Clear
oSelectSet.Select(ThisDoc.Path & "\cube\Cube1.ipt") 'Likely need to use an occurrence here instead

oControlDef1 = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_GroundAndRootComponentCmd") ' Missing quotes just like it says
oControlDef1.Execute

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 14 of 20

Sub Main
         oPartToAdd = "C:/Part.ipt"
         AddOccurrence(oPartToAdd)
End Sub

Public Sub AddOccurrence(oPartToAdd As String)
    ' Set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

    ' Set a reference to the transient geometry object.
    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    oMatrix = oTG.CreateMatrix

    ' Set the rotation of the matrix for a 45 degree rotation about the Z axis.
    Call oMatrix.SetToRotation(3.14159265358979 / 4, _
                            oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))

    ' Set the translation portion of the matrix so the part will be positioned
    ' at (3,2,1).
    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))

    ' Add the occurrence.
    Dim oOcc As ComponentOccurrence
    oOcc = oAsmCompDef.Occurrences.Add(oPartToAdd, oMatrix)

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef1 As ControlDefinition

Dim oSelectSet As SelectSet
oSelectSet = oDoc.SelectSet
oSelectSet.Clear
oSelectSet.Select(oOcc)

oControlDef1 = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_GroundAndRootComponentCmd")
oControlDef1.Execute End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 15 of 20

My last reply should work as an alright starting point. From there, you may need to tweak the placement of the parts.

Ps. "I'm not a programmer" also applies to me as well. I'm just an engineer who took 1 computer science course in my life, and spent some time learning myself by utilizing the abundance of resources out there for vb.net programming in inventer (ie; the forums, the Programming Help within inventor, StackOverflow forums, and MSDN website.)

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 16 of 20
S7RM7RPR
in reply to: MechMachineMan

Error in rule: Rule2, in document: Assembly2.iam

No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef1 As ControlDefinition

Dim oSelectSet As SelectSet
oSelectSet = oDoc.SelectSet
oSelectSet.Clear
oSelectSet.Select(ThisDoc.Path & "\cube\Cube2.ipt") 'ThisDoc.Path & "\cube\Cube2.ipt"

oControlDef1 = oCommandMgr.ControlDefinitions.Item("AssemblyBonusTools_GroundAndRootComponentCmd")
oControlDef1.Execute
Message 17 of 20
S7RM7RPR
in reply to: S7RM7RPR

Here is an example file of what I have set up and I'm getting the error posted in the previous message.

 

I'm using 2015 btw

 

This exmple is a cube, that creates more cubes, to create a cubed cube using the quantity you specify in the XYZ range. Yes, it amuses me. More importantly, if I can get this to work I can apply it to nearly anything.

 

Side note, the project I'm developing this for is far far more complicated. If I can get this to work I will be able to use it to self-replicate an assembly that will require over 10,000 unique variables with somewhere around 1,000 parts. So if this works, it will significantly decrease the file size and setup required.

Message 18 of 20
MechMachineMan
in reply to: S7RM7RPR

Your issue is that you have a document object selected and that's what you call in oSelectSet.Select.

You have to pass it an occurrence instead.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 19 of 20
S7RM7RPR
in reply to: MechMachineMan

I apologize, you've lost me there. I haven't done anything with occurances to my knowledge.

Message 20 of 20
MechMachineMan
in reply to: S7RM7RPR

Looks like you can just set the position when you insert the part.
This is a starting point. You are going to have to figure out/set the matrix to however you need it to properly insert the parts.
Good luck.
_____________________________________________________

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oPos As Matrix
oPos = ThisApplication.TransientGeometry.CreateMatrix()

  Dim oOccurrences As Occurrences = oDoc.COmponentDefinition.ComponentOccurrences

  oOccurrences.Add(ThisDoc.Path & "\cube\Cube2.ipt", oPos)

 

______________________________________________________


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type

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

Post to forums  

Autodesk Design & Make Report