Autodesk ObjectARX
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
HEllo, I want to ask a question of Parametric Drawing using objectarx 2010。
I define a user Variables in autocad2010(such as variableaa=10),I want to use the variable to drive the dimension of a line。
Now I want to change the value of variableaa through objectarx2010,can you tell me how to change the value of variableaa through objectarx2010 ? can you tell me the code?
thank you very much!
Solved! Go to Solution.
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi...
You can use ads_getsym and ads_putsym
Regards.
[source=c++arx]
#define tchar ACHAR *
int
lspfn_setqE(const tchar variabile,ads_name *puiubrat)
{ int rr;
static struct resbuf * a1;
rr=RTREJ;
a1=nil;
if (variabile==nil) //euaici: aici seteaza variabila din lisp
return(rr);
a1 = ads_buildlist(RTENAME,puiubrat, NULL);
rr = ads_putsym(variabile, a1);
ads_relrb(a1);
a1 = nil;
return(rr);
};
inline int
/*FCN*/lspfn_setqA(const tchar variabile,int vashort)
{ int rr;
static struct resbuf * a1;
rr=RTREJ;
a1=nil;
if (variabile==nil) //euaici: aici seteaza variabila din lisp
return(rr);
a1 = ads_buildlist(RTSHORT, vashort, NULL);
rr = ads_putsym(variabile, a1);
ads_relrb(a1);
a1 = nil;
return(rr);
};
[/source=c++arx]
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Firstly,Thank you very much!
but I can't understand your code ,I am a beginner,I can not find the function "ads_buildlist" in objectarx2010 Help。
I think the class "AcDbAssocVariables 、AcDbAssoc2dConstraintGroup、AcExplicitConstraint" is helpful,but I don't know how to use them。
Thanks again!
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
// (C) Copyright 2002-2007 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // //----------------------------------------------------------------------------- //----- acrxEntryPoint.cpp //------------------------------------------------ ----------------------------- #include "StdAfx.h" #include <AcDbAssocNetwork.h> #include <AcDbAssocVariable.h> #include "resource.h" //------------------------------------------------ ----------------------------- #define szRDS _RXST("") //------------------------------------------------ ----------------------------- //----- ObjectARX EntryPoint class CTestAssocApp : public AcRxArxApp { public: CTestAssocApp () : AcRxArxApp () {} virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) { // TODO: Load dependencies here // You *must* call On_kInitAppMsg here AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ; // TODO: Add your initialization code here return (retCode) ; } virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) { // TODO: Add your code here // You *must* call On_kUnloadAppMsg here AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ; // TODO: Unload dependencies here return (retCode) ; } virtual void RegisterServerComponents () { } static void ListVarsInNetwork(const AcDbAssocNetwork *pNet) { AcDbObjectIdArray idsActions = pNet->getActions(); for (int i = 0; i < idsActions.length(); i++) { AcDbObjectPointer<AcDbAssocAction> pAction(idsActions[i],AcDb::kForRead); if (pAction.openStatus() == Acad::eOk) { AcDbAssocNetwork *pNetSub = AcDbAssocNetwork::cast(pAction.object()); AcDbAssocVariable *pVar = AcDbAssocVariable::cast(pAction.object()); if (pNetSub) { ListVarsInNetwork(pNetSub); } else if (pVar) { acutPrintf(_T("\nVariable Name=%s Value=%s"), pVar->name().kACharPtr(), pVar->expression().kACharPtr()); } } } } static int GetVars(const AcDbAssocNetwork *pNet, AcStringArray &names, AcDbObjectIdArray &ids) { AcDbObjectIdArray idsActions = pNet->getActions(); for (int i = 0; i < idsActions.length(); i++) { AcDbObjectPointer<AcDbAssocAction> pAction(idsActions[i],AcDb::kForRead); if (pAction.openStatus() == Acad::eOk) { AcDbAssocVariable *pVar = AcDbAssocVariable::cast(pAction.object()); if (pVar) { names.append(pVar->name()); ids.append(pVar->objectId()); } } } return ids.length(); } // // Command list all AssocVariable // static void TestAssocListAssocVars(void) { AcDbObjectId idNet = AcDbAssocNetwork::getInstanceFromDatabase(acdbCurD wg(),true); AcDbObjectPointer<AcDbAssocNetwork> pNet(idNet,AcDb::kForRead); if (pNet.openStatus() != Acad::eOk) return; ListVarsInNetwork(pNet.object()); } // // Command Add new AssocVariable or change existent // static void TestAssocAddAssocVar(void) { // Add your code for command TestAssoc.AddAssocVar here Acad::ErrorStatus es; AcDbDatabase *pCurDb = acdbCurDwg(); AcDbObjectId idNet = AcDbAssocNetwork::getInstanceFromDatabase(pCurDb,t rue); AcDbObjectPointer<AcDbAssocNetwork> pNetMain(idNet,AcDb::kForRead); if (pNetMain.openStatus() != Acad::eOk) return; AcDbObjectIdArray ids = pNetMain->getActions(); AcDbObjectId idNetSub; if (ids.length() == 0) { AcDbAssocNetwork *pNetSub = new AcDbAssocNetwork(); if (pNetMain->upgradeOpen() == Acad::eOk) { if (pCurDb->addAcDbObject(idNetSub,pNetSub) == Acad::eOk) { pNetSub->addAction(idNetSub,true); pNetSub->close(); } else { delete pNetSub; } pNetMain->downgradeOpen(); } } else { idNetSub = ids[0]; } ACHAR name[512], val[512]; if (acedGetString(TRUE,_T("Variable name: "), name) != RTNORM || acedGetString(TRUE,_T("Variable expression: "), val) != RTNORM) { return; } AcDbObjectPointer<AcDbAssocNetwork> pNet(idNetSub,AcDb::kForWrite); if (pNet.openStatus() != Acad::eOk) return; AcString nameStr = name, valStr = val, errorMsg; AcStringArray sVarNames; AcDbObjectIdArray idsVars; GetVars(pNet.object(), sVarNames, idsVars); int ivar = 0; if (sVarNames.find(name, ivar)) { // Variable exist - change it AcDbObjectPointer<AcDbAssocVariable> pVar(idsVars[ivar], AcDb::kForWrite); if (pVar.openStatus() == Acad::eOk) { if (pVar->validateNameAndExpression(name,val,errorMsg ) != Acad::eOk) { acutPrintf(_T("\nError %s"), errorMsg.kACharPtr()); return; } if ((es = pVar->setExpression(valStr,_T(""),true,true,errorM sg,true)) != Acad::eOk) { acutPrintf(_T("\npVar->setExpression(valStr))=%s error=%s"),\ acadErrorStatusText(es), errorMsg.kACharPtr()); return; } } } else { AcDbAssocVariable *ppVar = new AcDbAssocVariable(); AcDbObjectId idVar; if (pCurDb->addAcDbObject(idVar,ppVar) == Acad::eOk) { ppVar->close(); pNet->addAction(idVar,true); } else { delete ppVar; return; } AcDbObjectPointer<AcDbAssocVariable> pVar(idVar, AcDb::kForWrite); if (pVar.openStatus() == Acad::eOk) { if (pVar->validateNameAndExpression(name,val,errorMsg ) != Acad::eOk) { acutPrintf(_T("\npVar->validateNameAndExpression(n ame,val,errorMsg) = %s"), errorMsg.kACharPtr()); pVar->close(); pNet->removeAction(idVar,true); return; } if ((es = pVar->setName(nameStr,true)) != Acad::eOk) { acutPrintf(_T("\npVar->setName(nameStr,true)=%s error=%s"),\ acadErrorStatusText(es), errorMsg.kACharPtr()); pVar->close(); pNet->removeAction(idVar,true); return; } if ((es = pVar->setExpression(valStr,_T(""),true,true,errorM sg,true)) != Acad::eOk) { acutPrintf(_T("\npVar->setExpression(valStr))=%s error=%s"),\ acadErrorStatusText(es), errorMsg.kACharPtr()); pVar->close(); pNet->removeAction(idVar,true); return; } } } } } ; //------------------------------------------------ ----------------------------- IMPLEMENT_ARX_ENTRYPOINT(CTestAssocApp) ACED_ARXCOMMAND_ENTRY_AUTO(CTestAssocApp, TestAssoc, ListAssocVars, ListAssocVars, ACRX_CMD_TRANSPARENT, NULL) ACED_ARXCOMMAND_ENTRY_AUTO(CTestAssocApp, TestAssoc, AddAssocVar, AddAssocVar, ACRX_CMD_TRANSPARENT, NULL)
Also a great sample: http://adndevblog.typepad.com/adnassocconstraintap
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
firstly thank you very much!
Then I'm so sorry,I can't understand your code,your code is very complex.
In order to achieve my aim,I think there is three steps;
1 open the database of the DWG file(but I don't know the function );
2 search the user parameter of autocad2010;(I don't know the function );
3 change the value of the user parameter;(I don't know the function );
I think the class "AcDbAssocVariables 、AcDbAssoc2dConstraintGroup、AcExplicitConstraint"
is helpful,but I don't know how to use them。
Can you tell me the code?
thank you very much!
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
1. Have you tried to build my code?
2. Have you tried to run commands ListAssocVars and AddAssocVar?
3. This is exactly the variables of which you speak? There are also AutoCAD system variables and lisp-variables.
It is very difficult to understand what you want without the dwg-file and a detailed description of what the drawing contains and how this must be replaced.
Without answers to these questions I will not try to help you.
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thank you very much! It's very kind of you.
this is a screenshot of the dwg-file。I want to change the value of user1 through objectarx2010(user1 is a User Variables),my purpose is to change the length of the line.could you tell me the code ? Thank you very much!
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,zhangxinhua789!
Please attach this dwg-file to your post in order to I can test my code with it.
ok
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: how to change the value of user variable of autocad201 0
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content





