Is it possible to insert a newly created part (without save) into an assembly?

Is it possible to insert a newly created part (without save) into an assembly?

liminma8458
Collaborator Collaborator
752 Views
7 Replies
Message 1 of 8

Is it possible to insert a newly created part (without save) into an assembly?

liminma8458
Collaborator
Collaborator

Hi, everyone,

 

I am creating a part document from a custom part template using such as:

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, "C:\3D\......\my_std_part.ipt", False)

 

Before saving it, I want to assemble it into an assembly using (the purpose of this is to preview how this new part fit in the assembly first, then decide keep it or not):

oOcc = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Add(full_path_file_name, oPositionMatrix)

 

Because I do not save it yet, this oPartDoc only has a name such as Part1, Part2 and so on assigned by system, but without a full path name. So is it possible adding this oPartDoc into an assmebly, and save it later?

 

Thank you very much in advance.

 

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Accepted solutions (1)
753 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

Hi,

 

First create the part separately.

then add it to your assembly.

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 8

liminma8458
Collaborator
Collaborator

I mean how to use API to do it. Even you do it manually, looks like you need to save the part file first then assemble it.

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor

Public Sub d()
Dim a As Application
Set a = ThisApplication

Dim ba As AssemblyDocument
Set ba = a.ActiveDocument

'Set b = a.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim bp As PartDocument
Set bp = a.Documents.Add(kPartDocumentObject, , True)

Call bp.SaveAs("D:\Test.ipt", False)

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oMatrix As Matrix
Set oMatrix = oTG.CreateMatrix

Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))
' Add the occurrence.
Dim oOcc As ComponentOccurrence
Set oOcc = oAsmCompDef.Occurrences.Add("D:\Test.ipt", oMatrix)


End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 8

liminma8458
Collaborator
Collaborator

bradeneurope,

 

Thank you very much for your code. As in your code, we have to "Call bp.SaveAs("D:\Test.ipt", False)" to save bp (PartDocument) to a specific name ("D:\Test.ipt") in disc first, then we can use this name as a handle to assemble it (Set oOcc = oAsmCompDef.Occurrences.Add("D:\Test.ipt", oMatrix)).

 

But my problem is that I don't know whether this bp (PartDocument) is what I want. I just want to see it in the assembly first, then I can decide to save it later or just skip it

 

My challenge is whether we can do something to add bp (PartDocument) directly  like:

Set oOcc = oAsmCompDef.Occurrences.Add(bp, oMatrix)

 

Any way to do it?

 

Thanks again

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Message 6 of 8

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Simply delete the file from disc if you do not want to keep it!!!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 8

liminma8458
Collaborator
Collaborator
Accepted solution

Bradeneurope:

 

Thank you for giving me the hint. I got it work the way I want by modifying your code as:

Public Sub d()
Dim a As Application
Set a = ThisApplication

Dim ba As AssemblyDocument
Set ba = a.ActiveDocument

'Set b = a.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim bp As PartDocument
Set bp = a.Documents.Add(kPartDocumentObject, , True)

'Call bp.SaveAs("D:\Test.ipt", False)

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oMatrix As Matrix
Set oMatrix = oTG.CreateMatrix

Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))
' Add the occurrence.
Dim oOcc As ComponentOccurrence
'Set oOcc = oAsmCompDef.Occurrences.Add("D:\Test.ipt", oMatrix)
Set oOcc = oAsmCompDef.Occurrences.AddByComponentDefinition(bp.ComponentDefinition, oMatrix)

ba.Activate
End Sub

 

Thanks again

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

Message 8 of 8

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Thank you for the Hint!

 

Dim a As Application
Set a = ThisApplication
Dim ba As AssemblyDocument
Set ba = a.ActiveDocument
'Set b = a.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim bp As PartDocument
Set bp = a.Documents.Add(kPartDocumentObject, , True)
'Call bp.SaveAs("D:\Test.ipt", False)
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oMatrix As Matrix
Set oMatrix = oTG.CreateMatrix
Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))
' Add the occurrence.
Dim oOcc As ComponentOccurrence
'Set oOcc = oAsmCompDef.Occurrences.Add("D:\Test.ipt", oMatrix)
Set oOcc = oAsmCompDef.Occurrences.AddByComponentDefinition(bp.ComponentDefinition, oMatrix)

Added this line of code? ba.Activate

I need to be more careful before I release my ideas and solution.

 

Good job.

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes