API for MBD

API for MBD

wgraham
Advocate Advocate
677 Views
2 Replies
Message 1 of 3

API for MBD

wgraham
Advocate
Advocate

Has anyone found a good way to promote dimension constraints to MBD/3DA?  There is a PromoteParameter property associated with the ModelDimensionDefinition, but it doesn't appear to be usable.  The closest thing I've found it so manually select the parameters needed, and execute the built in command.  This doesn't work well from inside one of my commands due to undo/redo requirements and makes managing a individual dimension constraint one at at time really awkward.  Snippet of the best I've been able to make actually work, but as stated earlier undo/redo gets lost.

 

Dim pdoc as PartDocument

Set pdoc = ThisApplication.ActiveDocument

 

Dim modeldims as ModelDimension

set modeldims = pdoc .ComponentDefinition.ModelAnnotations.ModelDimensions

 

Dim i as Integer

Set i = modeldims.Count

 

pdoc.SelectSet.Set({1+ Dimensions})

 

Call ThisApplication.CommandManager.ControlDefinitions("3daPromoteDimensionCmd").Execute

 

for j = i+1 to modeldims.Count

    Dim newannotation = modeldims(j)

    {Do something with newannotation}

next

 

Wouldn't expect it to be quite this painful to convert a dimension to model annotation.  One help would be appreciated.

 

Thanks,

William Graham

 

0 Likes
Accepted solutions (1)
678 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Hello mr Graham,

 

I have recently done the same thing, but sadly in a way more complicated method. While my method did not require the usage of commands, I pretty much created a new Annotation on the same entities on which the sketch dimension was created. It works, but for every type of sketch dimension constraint, a seperate handler for the annotation had to be created. (like diameter constraint to diametermodeldimension annotation). 

However, I can help you a bit with your undo issue. By using the transactionmanager, you can make the code run as one single undo action. This works like this (in VBA):

 

sub yourFunction()
   Dim oTrans as Transaction
   set oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "just some name")
   On Error Goto ErrorHandler
   'place here your code, or at least all action related code
   'make sure you do NOT call Exit sub here
   Call oTrans.end
   Exit sub
ErrorHandler:
   Call oTrans.abort
end sub

 Special warning here: you MUST either end or abort the transaction in this routine, hence the reason I included an error handler in the code. if this is not done, your instance of inventor will pretty much crash. Hence the reason why you cannot use exit sub without calling oTrans.end first. if this does happen somehow, you can still write a new function and use this line:

Call thisapplication.transactionmanager.currenttransaction.abort

To save your work.

 

Hope this helped,

Peter Verheijen

0 Likes
Message 3 of 3

wgraham
Advocate
Advocate
Accepted solution

Peter,

Thanks for the reply.  I was aware of the transaction option, but it doesn't play well with my overall coding plan.  Initiating a new command while a change request is in progress cancelling the current command.  For what it's worth, below is a recap of what I figured out late yesterday to make things work.  Essential steps are as follows.

  1.  Create ModelDimensionDefinition(Linear, Diameter, Angle)
  2.  Add PromoteParameter to definition (must occur before adding as modeldimension)
  3. Add definition and modeldimension

Strangely enough, started creating independent model dimension rather than promoting sketch/model parameters.  Noticed that if a sketch parameter is promoted the ability to change annotation planes and pull into a different drawing view is fairly limited.  The most robust way to make it work fairly independently is attached work points to sketch points and attach 3D model annotations to the work points.  This allows work points to be redefined to new locations with out losing the reference.  It's a fairly heavy handed work around, to get the best of 3D and 2D annotation, but it works.

 

Thanks,

William Graham

0 Likes