Copy and paste

Copy and paste

GeorgK
Advisor Advisor
937 Views
15 Replies
Message 1 of 16

Copy and paste

GeorgK
Advisor
Advisor

Hello together,

 

is it possible to copy parts / assemblys and paste them at given point?

 

Georg

0 Likes
938 Views
15 Replies
Replies (15)
Message 2 of 16

adam.nagy
Autodesk Support
Autodesk Support

Hi Georg,

 

The API does not provide a functionality like that directly.

 

However, you can create a new instance which is based on the same definition as the existing occurrence, then set its transformation to whatever you need.

 

Cheers, 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 16

Crstiano
Collaborator
Collaborator

Hi Adam,

Do you have an example for copy " 2 parts constrained" and paste in the same assembly.

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Cristiano Oliveira
EESignature
ConsultCAD.com

0 Likes
Message 4 of 16

GeorgK
Advisor
Advisor

Hello Adam,

 

I am also interested in a solution.

 

Georg

0 Likes
Message 5 of 16

Jef_E
Collaborator
Collaborator

I use this to copy a sketch to a workplane in a part document. But my guess is it could also be used to copy parts.

 

Dim Part1 As part component = ...

Dim Part2 As part component = ...

 

paste?

 

        ' Select sketch
        Dim oSketchToCopy As PlanarSketch = oDef.Sketches.Item("Vorm_C1")
        Call oDoc.SelectSet.Clear()
        Call oDoc.SelectSet.Select(oSketchToCopy)

        ' copy sketch
        Dim oCopyControlDef As ControlDefinition = oInvApp.CommandManager.ControlDefinitions.Item("AppCopyCmd")
        oCopyControlDef.Execute()

        ' Select workplane for paste sketch
        Call oDoc.SelectSet.Clear()
        Call oDoc.SelectSet.Select(oNewplane)

        ' Paste sketch
        Dim oPasteControlDef As ControlDefinition = oInvApp.CommandManager.ControlDefinitions.Item("AppPasteCmd")
        oPasteControlDef.Execute()


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 6 of 16

Crstiano
Collaborator
Collaborator

Maybe not the best way, but a brutal way for execute that. 😉

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Cristiano Oliveira
EESignature
ConsultCAD.com

0 Likes
Message 7 of 16

Owner2229
Advisor
Advisor

Hi, I believe that you can modifi the code below to your needs. Or just tell me what else you want it to do and I'll rewrite it for you.

You can specify the file name in highlighted part of code. It works for both assemblies and parts.

You can change the point where the part/assembly will be placed in the second highlighted part of code.

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim Acd As ComponentOccurrencesEnumerator = oAsmCompDef.Occurrences.AllLeafOccurrences Dim Occ As ComponentOccurrence
For Each Occ In Acd ModelFileName = Occ.Definition.Document.FullFileName
FNamePos = InStrRev(ModelFileName, "\", - 1)
docFName = Mid(ModelFileName, FNamePos + 1, Len(ModelFileName) - FNamePos)
If docFName = "MyWantedAssembly.iam" Then Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oMatrix As Matrix = oTG.CreateMatrix Call oMatrix.SetToRotation(3.14159265358979 / 4, _ oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0)) Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1)) Dim oOcc As ComponentOccurrence oOcc = oAsmCompDef.Occurrences.Add(ModelFileName, oMatrix)
Exit Sub
End If
Next

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 8 of 16

GeorgK
Advisor
Advisor

Hello Mike,

 

thanks for the solution. But is it possible to copy 2 or more parts with the constraints and paste them at a given position?

 

Thank you

 

Georg

0 Likes
Message 9 of 16

Owner2229
Advisor
Advisor

Hi, it is possible, but first I need to know if you want to copy these parts by name (as in my code above) or from selection.

I can also place there an input box and you would write the wanted part/assembly names (with or without extensions).

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 10 of 16

GeorgK
Advisor
Advisor

It would be great to have both solutions. One with the names  and one with the selection.

0 Likes
Message 11 of 16

Jef_E
Collaborator
Collaborator

@Crstiano wrote:

Maybe not the best way, but a brutal way for execute that. 😉


Could you please show me a better way to do this? I'm always looking to improve, and be less brutal 😄



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 12 of 16

Crstiano
Collaborator
Collaborator

I say this because after running the "paste", I need to identify one of the inserted parts, and this way I still do not know how to do!

I do not want to have to keep the whole list of pre-existing items and then find the newly inserted.

 

So I think the best way is through a collection, but I'm standing (blind) in the way of inserting the collection (with constraints) again and controls it.

 

I accept suggestions.

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Cristiano Oliveira
EESignature
ConsultCAD.com

0 Likes
Message 13 of 16

adam.nagy
Autodesk Support
Autodesk Support

Executing the ControlDefinition for copying is the simplest solution.

You just have to make sure that the Model view window is active otherwise nothing will happen.

 

The other way would be much more cumbersome as you would have to copy over each component occurrence and then check the constraints between them and then recreate them in the new document. 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 14 of 16

Crstiano
Collaborator
Collaborator
As I said before, it would not be possible to insert a collection (with constraints)?

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Cristiano Oliveira
EESignature
ConsultCAD.com

0 Likes
Message 15 of 16

Jef_E
Collaborator
Collaborator

Well, I still think you can, someone once wise once said: "If you can do it by hand, you can do it by code" But sometimes it just needs a big workaround, to do something small.

 

So the question still remains:

Can you copy 2 parts within a assembly that are constraint to each other, and paste them keeping the constraints?

 

Can it be done by hand? Yes, since 2014?

Select items + copy and paste --> simple as that..

 

My code may be robust, but it does just that, but it raises another problem, find the latest placed. Could be me, but wouldn't these be the last 2 components in the collection? If you check the count and lets say its 10.. wouldn't 9+10 be your match? (just a idea, got no clue if it is that simple)



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 16 of 16

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Yes I think it should be that simple that the last components are the newly created ones:

http://adndevblog.typepad.com/manufacturing/2015/11/copy-occurrences-with-constraints.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes