New Assembly, drop current partdocument in, activate "Change Size . . "

New Assembly, drop current partdocument in, activate "Change Size . . "

Anonymous
Not applicable
638 Views
9 Replies
Message 1 of 10

New Assembly, drop current partdocument in, activate "Change Size . . "

Anonymous
Not applicable
I need to quick-like whip up a macro to do the following:

- Start a new assembly based on the default assembly template.
- Drop the current part into the assembly
- Activate the "Change Size . . " command, assuming the part is a custom CC part.

Can anyone give me a few quick hints or a starting point?
0 Likes
639 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Try the macro below. I simply re-activated the part
at the end instead of closing the temp assembly, since a document close results
in truncating the undo chain. That's typically not desirable.

 

Sanjay-

 

 

Sub ChangeSize()
   

    Dim oPart As PartDocument
    Set oPart
= ThisApplication.ActiveDocument
   
   
Dim oAssembly As AssemblyDocument
    Set oAssembly =
ThisApplication.Documents.Add(kAssemblyDocumentObject)
   

    Dim oDef As
AssemblyComponentDefinition
    Set oDef =
oAssembly.ComponentDefinition
   
    Dim
oMat As Matrix
    Set oMat =
ThisApplication.TransientGeometry.CreateMatrix
   

    Dim oOcc As ComponentOccurrence
    Set
oOcc = oDef.Occurrences.Add(oPart.FullDocumentName, oMat)
   

    Call
oAssembly.SelectSet.Select(oOcc)
   
   
Dim oCtrlDef As ControlDefinition
    Set oCtrlDef =
ThisApplication.CommandManager.ControlDefinitions.Item("CCV2ChangeSizeButtonCM")
   

    oCtrlDef.Execute
  
   
DoEvents
    oPart.Activate
   
End
Sub
0 Likes
Message 3 of 10

Anonymous
Not applicable
Wow Oh my Gosh that works Great!! My wife is over here looking at me funny. I'm tickled pink!! WOOHOO! Thank you sir! That's perfectly exactly what I was struggling to do all night. I sat up fiddling with VBA until like 2am last night and couldn't get very far.

Thank you!
0 Likes
Message 4 of 10

Anonymous
Not applicable
Sanjay, et al,

This macro now hiccups on my 64bit workstation for some reason. I figured maybe it was outpacing the server where the Content Center resides so I put a bunch of 5 second pauses into it - no dice.

When it fails, I'm in the part and I get a message that says:
_____________________________________________________________
Select Library:

There was a problem encountered while communicating with the
server. Please check the network connection and server status.

OK
______________________________________________________________

I get this same message even if I put a 5 second pause after every single line of code!

When I click ok I flip to the Assembly and the macro stops. I was pretty sure I was onto something with adding the pauses but I still cannot get it to work.

The only way I've found is to comment out the last line that activates the part (oPart.Activate), and then it just stops after I ChangeSize on the part. I get left in the Assembly and I have to close it or switch back over to the part.

Any clues?
0 Likes
Message 5 of 10

Anonymous
Not applicable
I suspect the problem may be something else. Have you tried executing (all)
the steps manually, instead of the API?

Sanjay-
0 Likes
Message 6 of 10

Anonymous
Not applicable
I can step thru the macro (F8) successfully. Odd, eh?
0 Likes
Message 7 of 10

Anonymous
Not applicable
Try this:

replace DoEvents with ThisApplication.UserInterfaceManager.DoEvents

Sanjay-
0 Likes
Message 8 of 10

Anonymous
Not applicable
Thank you Sanjay, that worked. I guess 64bit requires things to be called out a little more specifically.
0 Likes
Message 9 of 10

Anonymous
Not applicable
This is the result of VBA being out of process in 64 bit version of
Inventor. See the following excerpt from programming help...

Sanjay-

VBA in 64-bit Inventor is implemented only as an out-of-process 32-bit
component. Therefore, for 64-bit Inventor, a 32-bit process is used to host
VBA. Thus all the API calls are out-of-process calls. This has several
implications:

1.. In some cases, API calls can cause Inventor to update its UI. This can
cause your VBA code to slow down. For long operations, where your code makes
multiple calls to Inventor, you can regain performance by disabling the
Inventor UI. To do so, set the UserInterfaceManager.UserInteractionDisabled
property. Please do this carefully, as you are responsible for resetting
this property afterwards. Note that this slowdown does not happen when your
code is responding to an event raised by Inventor.
2.. The FileManager.FileSystemObject property returns Microsoft's
scripting FileSystemObject which is instantiated in Inventor's process
space. Using FileSystemObject directly in 64-bit space gives the wrong
current directory etc. Therefore you should avoid using built-in VBA
functions such as chdir$.
3.. To wait for Inventor to complete processing of pending windows
messages, you need to use UserInterfaceManager.DoEvents instead of the
builtin DoEvents subroutine in VBA.
4.. ThisDocument in Document projects is not supported. You can embed a
VBA project in any Inventor document. Usually in a macro within such a
project, you can use ThisDocument property to refer to the document itself.
With VBA for 64-bit Inventor, ThisDocument object no longer refers to the
document. Instead for 32 & 64 bit VBA compatibility, you will need to
manually replace all the references to ThisDocument by
ThisDocument.InventorDocument.
5.. No VB6 support for creating Addins You can not use VB 6.0 to create
Add-ins for 64 bit Inventor.
6.. Handles in 64-bit Windows are supposed to be 64-bit. However only the
lower 32-bits are significant and the rest are zero. Therefore
Application.MainFrameHWND returns 'long' type which works in 32-bit
Inventor. You just need to "zero out" the higher bits. You can use the
handle in a 32-bit process as well.
7.. Application.GetInterfaceObject32 creates the COM in-proc server object
in the 32-bit host that is used to host VBA. It requires that if the typelib
is also registered in the 64-bit registry, then the methods and properties
should match.
8.. The ApplicationEvents.OnRestart32BitHost event is fired when the
32-bit host process is restarted for any reason.
9.. Some of the Inventor API methods and properties use IPictureDisp
interface when working with icons/images. This interface does not work
across process boundaries. Thus any such methods cannot be used in 64-bit
Inventor VBA.
10.. Use of Me in Document projects is not supported. You can embed a VBA
project in any Inventor document. Usually in a macro within such a project,
you can use Me property to refer to the document itself. On the VBA for
64-bit Inventor, Me object no longer refers to the document. Instead for 32
& 64 bit VBA compatibility, you will need to manually replace all the
references to Me by Me.InventorDocument.
0 Likes
Message 10 of 10

Anonymous
Not applicable
thank you. This is, in fact, most timely information with regard to other things I am into.
0 Likes