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.
Solved by Alexander.Rivilis. Go to Solution.
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]
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!
// (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(acdbCurDwg(),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,true); 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,errorMsg,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(name,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,errorMsg,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/adnassocconstraintapi.zip
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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!
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.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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!
Hi,zhangxinhua789!
Please attach this dwg-file to your post in order to I can test my code with it.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Ok. I've tested my code from post 4 and it do it the same you ask me.
1. Compile and build arx-file with code I've posted.
2. Start AutoCAD and load arx-file into AutoCAD.
3. Starting command ADDASSOCVAR and you see how line changed.
Command: ADDASSOCVAR Variable name: user1 Variable expression: 100
So before command:
And after command:
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Hello,experts
I have a new question,I want to know how to use the Dynamic Blocks in objectarx2010. I define a Dynamic Block in autocad2010,Now I want to insert the Dynamic Block in a dwg-file,can you tell me the code?Thank you very much!
this is a screenshot of the Dynamic Blocks,I want to insert the Dynamic Block in the position(x=50,y=50),and I want change the three dimensions:
before command:they are d1=48;d2=96;d3=43
after command:they are d1=98;d2=150;d3=70
I think the class of AcDbDynBlockReference is useful,but I don't know how to use it.Can you help me?
Hello,experts
I have a new question,I want to know how to use the Dynamic Blocks in objectarx2010. I define a Dynamic Block in autocad2010,Now I want to insert the Dynamic Block in a dwg-file,can you tell me the code,Thank you very much!
this is a screenshot of the Dynamic Blocks,I want to insert the Dynamic Block in the coordinate position(x=50,y=50),and I want change the three dimensions:
before command:they are d1=48;d2=96;d3=43
after command:they are d1=98;d2=150;d3=70
And I have attached this dwg-file in my post in order to you can test your code with it(I have
defined the the Dynamic Block,its name is a;you can try to insert it in autocad2010).
I think the class of AcDbDynBlockReference is useful,but I don't know how to use it.Can you help me?
Can't find what you're looking for? Ask the community or share your knowledge.