Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




LISP/ADS Support For the Autodesk Mechanical Desktop

autocad en


LISP/ADS Support For the Autodesk Mechanical Desktop

Autodesk Mechanical Desktop Commands

Invoking Mechanical Desktop Commands From LISP/ADS

Mechanical Desktop commands that are to be invoked through acedInvoke() should be done so via commands that are acedDefun() registered.



Before invoking a Mechanical Desktop command that has a dialog box, you need to set CMDDIA to zero. After the command is complete, restore CMDDIA to its original value. To support LISP/ADS input, the Mechanical Desktop commands are registered using acedDefun(). The following list shows the different ways a value can be provided for the Mechanical Desktop command prompts when invoked through ADS. From LISP the syntax will be different, but the types shown in this list are still valid. See the end of this section for examples.

Integer (acedGetInt)

RTSHORT, 2,

RTSTR, "2",

Value must be in decimal units.

Real (acedGetReal)

RTREAL, 0.5,

RTSTR, "0.5",

Value must be in decimal units.

Distance (acedGetDist or acedGetReal)

RTREAL, 0.5,

RTSTR, "0.5",

Value must be in decimal units.

Angle (acedGetString)

RTSTR, "0.5",

The value must be Radians if AUNITS is set to three or Decimal Degrees if AUNITS is set to zero.

Keyword (acedGetString)

RTSTR, "thru"

String (acedGetString)

RTSTR, "Section A-A"

Point & Corner (acedGetPoint)

RTPOINT, pt1

RT3DPOINT, pt2

Cannot pass a relative or polar value.

Single selection (acedEntSel or acedNEntSelP)

RTLB

:

:

:

RTLE

This list is the standard list containing the information returned from a call to entsel or nentselp.

For more specific information on the information contained in this list, see your AutoCAD documentation. If you manually construct this list, you must include, at least, the entity name and the pick location.

For example: RTLB

RTENAME

RTPOINT or RT3DPOINT

RTLE

For many of the Mechanical Desktop commands it might be necessary to use the point and re-select the entity to determine more specific information about what part of the entity was selected. If this re-selection is necessary, the entity must be visible and the viewport the entity was originally selected in must be the currently active viewport. If not, the command will either fail or result in unexpected behavior.

After you've finished providing single selections to a prompt that continues to loop and prompt you for another selection, use RTNONE, RTNIL or RTSTR and pass an empty string. (The AMFILLET command is an example of this.)

The assembly modeling commands are frequently looking for selections of entities contained within blocks. Thus, use nentselp instead of entsel when providing a selection.

Selection set (acedSSGet)

RTPICKS, ss

When a selection set is passed to one of the Mechanical Desktop commands, it is the caller's responsibility to make sure the set contains valid entity types that were selected with valid selection methods. Selection sets that contain invalid entity types or entities that were selected with invalid selection methods will cause the command to either fail or create unexpected results.

Many of the Mechanical Desktop commands take advantage of additional information that is only available with an original selection set returned from a call to ssget/acedSSGet. Avoid using ssadd/ads_ssadd to create a new selection set or add entities to an existing selection set that is going to eventually be used in a Mechanical Desktop command. In some situations this will not cause problems, but many of the Mechanical Desktop commands will not produce expected results.

Notes

When invoked through LISP, all of the Mechanical Desktop prompts will work with interactive prompting. To do this, provide the LISP prompt instead of the value. For example, instead of setting the sketch angle tolerance to a hardcoded value, it can be invoked through LISP so that it prompts you for the value.

(amskangtol 4.5) This assigns the value 4.5 to amskangtol.

(amskangtol (getreal))    This prompts you for the value to assign to amskangtol.

When invoked through LISP or ads, all of the Mechanical Desktop prompts will work if a variable of the appropriate type is provided instead of a hardcoded value. For example, a value can be prompted for earlier in the program, assigned to a variable, the variable can be modified, if needed, and the variable can be used when invoking the Mechanical Desktop command.

From LISP:

(setq angTol (getreal))

// Modify angTol if necessary.

(amskangtol angTol)

From Ads:

ads_real angTol;

status = acedGetReal("Enter value:", &angTol);

// Modify angTol if necessary.

struct resbuf *argList, *rslt;

argList = acutBuildList(RTSTR, "amskangtol",

RTREAL, angTol,

0);

status = acedInvoke(argList, &rslt);

Examples Invoking Mechanical Desktop Commands

Here are some examples of how you would invoke one of the Mechanical Desktop commands through LISP or ads.

From LISP:

(amhole "drill" "thru" 0.5 "no" "twoEdges" (entsel) (entsel) (getpoint) "1.0" "1.0")

or

(setq e1 (entsel))

(setq e2 (entsel))

(setq p1 (getpoint))

(amhole "drill" "thru" 0.5 "no" "twoEdges" e1 e2 p1 1.0 1.0)

or

(amhole "drill" "thru" 0.5 "no" "twoEdges" '(9.3 8.0) '(11.9 6.7) '(-1 -2) -1 -1)

From an ads program:

struct resbuf *argList, *rslt;

ads_point pt1, pt2, pt3;

pt1[0] = 9.3; pt1[1] = 8.0; pt1[2] = 0.0;

pt2[0] = 11.9; pt2[1] = 6.7; pt2[2] = 0.0;

pt3[0] = -1.0; pt3[1] = -2.0; pt3[2] = 0.0;

argList = acutBuildList(RTSTR, "amhole",

RTSTR, "drill",

RTSTR, "thru",

RTREAL, 0.5,

RTSTR, "no",

RTSTR, "twoEdges",

RT3DPOINT, pt1,

RT3DPOINT, pt2,

RT3DPOINT, pt3,

RTREAL, -2.0,

RTREAL, -1.0,

0);

status = acedInvoke(argList, &rslt);

System Variables

To get the value of a Mechanical Desktop system variable through LISP or ads, you need to invoke the system variable command without modifying its value. From LISP, the value of the Mechanical Desktop system variables can be obtained by invoking the system variable command and assigning the return value to the appropriate type. From an ads program, the value of the Mechanical Desktop system variables can be obtained from the result field of acedInvoke(). Below is a list of the system variables and the value types returned. At the end of this section are some examples.

Mechanical Desktop Part Modeling

AMCOMPSV

RTSHORT

AMCONDSPSZ

RTSHORT

AMRULEMODE

RTSHORT

AMSKANGTOL

RTREAL

AMSKMODE

RTSHORT

AMSKSTYLE

RTSTR

Drawing Manager

AMANNOTEPRESERVE

RTSHORT

AMCLCM

RTREAL

AMCLGAP

RTREAL

AMCLOSHT

RTREAL

AMCLPAR

RTSHORT

AMCLTYPE

RTSTR

AMDWGCOLOR

RTSHORT

AMHIDLTYPE

RTSTR

AMHLCALC

RTSHORT

AMLINETHICK

RTREAL

AMPROJTYPE

RTSHORT

AMREUSEDIM

RTSHORT

AMSECLTYPE

RTSTR

AMSECTIONDIM

RTSHORT

AMSTDDTL

RTSTR

AMSTDSCT

RTSTR

AMSTDTAP

RTSTR

AMVANISH

RTSHORT

AMVIEWREFRESH

RTSHORT

AMVPBORDER

RTSHORT

Assembly Modeler

AMAUTOASSEMBLE

RTSHORT

AMINSERTABS

RTSHORT

AMSCENEUPDATE

RTSHORT

AMVIEWRESTORE

RTSHORT

Mechanical Desktop Surfaces Modeling

AMBLENDTOL

RTREAL

AMGRPREFIX

RTSTR

AMINTERPOLY

RTSHORT

AMJOINGAP

RTREAL

AMPAGELEN

RTREAL

AMPFITANG

RTREAL

AMPFITLEN

RTREAL

AMPFITTOL

RTREAL

AMPROJOUTPUT

RTSHORT

AMSFDISPMODE

RTSHORT

AMSFTOL

RTREAL

AMULINES

RTSHORT

AMVECAUG

RTREAL

AMVECSF

RTREAL

AMVLINES

RTSHORT

Part Modeling

AMCMDDIM

RTSHORT

Miscellaneous

ACISOUTVER

RTSHORT

Getting the value of a system variable:

From LISP:

(setq vlines (amvlines ""))

or

(setq gap (amjoingap nil))

From ads:

struct resbuf *arglist, *rslt;

arglist = acutBuildList(RTSTR, "amskangtol",

RTSTR, "",

0);

retVal = acedInvoke(arglist, &rslt);

Integrating the MCAD API with Mechanical Desktop Commands

Implementation of the API is ongoing work, and much effort is targeted at providing extra functionality for developers building Autodesk Mechanical Desktop applications. It is expected that, for some time to come, you can only perform certain operations by calling the commands directly.

Calling Mechanical Desktop Commands

Until now, calling commands has presented serious problems for application developers because the commands are designed primarily for user interaction. Those commands that take entities or subentities as arguments require them to be selected from the screen. This places a large burden on the application, for example, to generate pick points and ensure that the picking will select entities uniquely.

An application already using the MCAD API might have need to call certain commands. The 'Keys' used within the MCAD API have to be queried in order that the application calls the commands with the right data.

Example

An application might have the key of an edge that it wants to fillet. It can only create the fillet by calling the command AMFILLET. This command requires that a pickpoint be specified, identifying the edge to be filleted. When used interactively, the user can change the view and inspect the part to determine how to pick the required edge. This is much harder to achieve within an application. Depending on the view, other edges might be hiding the required edge; thus, it might be difficult, or even impossible, for the application to identify the edge to be filleted.

The problem of integrating the MCAD API with the calling of commands has been solved. It is now possible to call the commands directly using the Keys generated within the MCAD API.

Benefits

The benefits of this enhancement are

Applications are more reliable.

Applications can be developed immediately, rather than waiting for future versions of the MCAD API.

Functionality accessible to developers using the MCAD API is dramatically improved.

Applications are more efficient.

Changes to the commands do not affect their use in any other way. If developers are not using the MCAD API, changes made are not visible. Any existing calls to commands continue to work unchanged.

Certain operations can be performed using the commands. This allows the developers of the MCAD API to concentrate on those aspects for which there is no command alternative. This ensures that the MCAD API developers can best meet the needs of third-party developers.

Usage Details

Using the MCAD API, users can generate Keys to certain entities within Mechanical Desktop. For example, the application might have obtained the Key to an edge, represented as an AmiCurveKey. If a Desktop command requires an edge to be specified (e.g., positioning a hole from two edges through AMHOLE), instead of trying to specify the edge to the command by getting the entity name and a point on the edge using the key and passing this information to the command, the Key can be passed directly to the command. The command would be called using acedInvoke, in the normal way.

acedInvoke takes a resbuf chain, which can be constructed using acutBuildList. Here, instead of identifying the edge using RTLB, RTENAME, pName, RT3DPOINT, pickPt, RTLE, use the sequence RTLB, RTLONG, 0, RTLONG, (long) pKey, RTLE. As stated above, the first way of calling the command continues to be supported as well.

Passing Additional Points

The normal method for calling the commands is to use the key, as described above. Certain commands, as well as requiring the key to identify which entity or subentity, require a point to indicate where on the subentity or entity the command should be applied. When this occurs, it is not sufficient to call the command just with the key, but the user also needs to pass in a point. This has to be done in a specific way.

You cannot simply add another resbuf to the chain containing the point. Instead, the long code that is passed into the command should be 1, rather than 0, and the second resbuf in the list should be a pointer to another resbuf chain, cast to a long. This resbuf chain should contain two resbufs. The first is the key, cast as a long. The second is a 3d Point. For example,

struct resbuf*pExtraRb = acutBuildList( RTLONG, (long) pKey,

RT3DPOINT, calculatedPoint, 0);

struct resbuf*pRb = acutBuildList( RTSTR, "AMPARDIM",

RTLB, RTLONG, 1, RTLONG, (long) pExtraRb, RTLE, ...);

As a rule of thumb, if the interactive command depends on the position of the pick, as well as the thing picked, then the command is using the pick point to specify this position, and you should use this alternative method for calling the commands.

NOTE: Passing the additional point, in the fashion described here, is not detrimental, even in the case of commands that do not require the extra information.

Sample Code

The attached sample code lets the user pick a face and then traverses through the edges of the face filleting all edges with the same radius.

int facefillet()

AcBrEntity* pBrEnt = NULL;

amiEs = amiGetBrepFromKey(pGeomKey, pBrEnt);

pKey->release();

AcBrFace* pFace = AcBrFace::cast(pBrEnt);

if(pFace == NULL)

if(amiEs != Ami::eOk)

return AcRx::kRetError;

double radius;

if(RTNORM != acedGetReal("\nPlease enter radius of fillet\n", &radius))

// now construct the calling list

struct resbuf* pCallingRb = acutBuildList(RTSTR, "", RTREAL, radius, 0);

// Some B-rep error handling omitted

AcBr::ErrorStatus brEs;

AcBrFaceLoopTraverser faLoTrav;

brEs = faLoTrav.setFace(*pFace);

if( brEs != AcBr::eOk )

// keep the keys somewhere, so they can be released later.

AcDbVoidPtrArray keyArray;

for(;!faLoTrav.done(); faLoTrav.next())

for(;!loEdTrav.done();loEdTrav.next())

struct resbuf* pRb = acutBuildList(RTLB, RTLONG, 0,

RTLONG, (long) pEdgeKey, RTLE, 0 );

pRb->rbnext->rbnext->rbnext->rbnext = pCallingRb;

pCallingRb = pRb;

keyArray.append( pEdgeKey );

}

}

delete pFace;

struct resbuf*pRb = acutBuildList(RTSTR, "AMFILLET", 0);

pRb->rbnext = pCallingRb;

pCallingRb = pRb;

struct resbuf* pResRb = NULL;

if(acedInvoke( pCallingRb, &pResRb ) != RTNORM)

int nKeys = keyArray.length();

acutPrintf("Applied Fillet with radius %lf to %d edges\n", radius, nKeys );

for( int i=0; i< nKeys; i++ )

((AmiObjectKey*)(keyArray.at(i)))->release();

// end of function

return AcRx::kRetOK;


Document Info


Accesari: 2601
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )