ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating associative hatch

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
igor.ivanov
927 Views, 11 Replies

Updating associative hatch

Hello.

 

I have problems width assosiative hatches updating. There is simple dwg file width closed polyline and hatch which is assosiated to it. My arx program opens this dwg translate everything by using AcDbEntity::transformBy() and saves the dwg to different directory. Everything working fine except hatch, the boundary polyline is transformed to new coordinates but the hatch does not. If I open transformed dwg and move some polylines points the hatch "come back" in other words assosiativity works then, but why it is not working when polyline is changed trough code? I do not zoom to extents when dwg is opened is it problem? In my code if Hatch is associative transformBy not called to Hatch becouse it supposed to be updated by persistent reactor mechanism, but it does not seems to work. How can I force the Hatch to be updated....

 

Thanks

Igor

11 REPLIES 11
Message 2 of 12
owenwengerd
in reply to: igor.ivanov

You say you "transform everything", but then you seem to imply that you do not transform the hatch. Are you transforming the hatch entity or not? It may be that updating hatches requires graphics to have been generated. This is not possible in all contexts. In what context are you calling transformBy()?

--
Owen Wengerd
ManuSoft
Message 3 of 12
igor.ivanov
in reply to: owenwengerd

Hi

I was incorrect in my words, it does not transform everything, if hatch->associative() == true -> nothing is done for hatch.

The command is registered width ACRX_CMD_SESSION so it is in application context(it must be). What should I do?

 

Thanks

Igor

Message 4 of 12
owenwengerd
in reply to: igor.ivanov

Sorry, I can't solve the problem for you, I'm just trying to help you find the cause. I recommend to create a simple test command that does nothing but transform the polyline. If that simple test fails to update the hatch, I would try it in document context to see if application context is the problem. If the simple test works as expected, then you'll need to start adding things until you identify the cause. If the simple test fails, then you can post the code here so that someone else may investigate.

--
Owen Wengerd
ManuSoft
Message 5 of 12
owenwengerd
in reply to: owenwengerd

Just a thought: you might try calling AcDbHatch::evaluateHatch() to see if that triggers an update.

--
Owen Wengerd
ManuSoft
Message 6 of 12
igor.ivanov
in reply to: igor.ivanov

Now I did little more research and wrote little test program. The code is below. The problem is that the test file is opened trough COM and this seems to be the problem, becouse when I open file by File->Open and do transformation in CMD_SESSION command everything works fine, but when it is like in the example the polyline is moved but not the hatch. Any suggestions?

PS. evaluateHatch does not work.

 

#import"C:\\Program Files\\Common Files\\Autodesk Shared\\acax19enu.tlb" no_namespace

......

......

......

// Application Session Command with localized name

// ACED_ARXCOMMAND_ENTRY_AUTO(CTestEntUIApp, BPMyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION)

staticvoid BPMyGroupMySessionCmd () {

// Put your command code here

Acad::ErrorStatus AcRes;

AcGePoint3d pt;

AcDbObjectId oid;

IAcadApplicationPtr acadApp;

LPDISPATCH pDispDocs = NULL;

LPDISPATCH pDispDoc = NULL;

IAcadDocumentsPtr acadDocs;

IAcadDocumentPtr acadDoc;

//this is the test file width closed polyline and hatch assosiated to it

CString s_FileName = _T("c:\\temp\\AssHatch.dwg");

if(acadApp = acedGetAcadWinApp()->GetIDispatch(TRUE))

{

variant_t b(VARIANT_FALSE);

acadDocs = acadApp->Documents;

if(acadDocs)

{

acadDoc = acadDocs->Open((LPCTSTR)s_FileName, b);

if(acadDoc == NULL)

{

acutPrintf(_T("\nCan not open %s file in ACAD."),s_FileName);

return;

}

}

else

{

acutPrintf(_T("\nacaddocs false"));

return;

}

}

else

{

acutPrintf(_T("\n acadapp false"));

return;

}

 

AcGeMatrix3d mat;

mat.setToTranslation(AcGeVector3d(15600000,100000550,0));

AcRes= acDocManager->lockDocument(curDoc());

if(AcRes!=Acad::eOk)

{

acutPrintf(_T("\nlockDocument -> %s"),::acadErrorStatusText(AcRes));

return;

}

AcDbBlockTableRecordPointer pRec(ACDB_MODEL_SPACE,curDoc()->database(),AcDb::kForRead);

if((AcRes = pRec.openStatus()) != Acad::eOk)

{

acutPrintf(_T("\npRec.openStatus -> %s"),::acadErrorStatusText(AcRes));

return;

}

 

AcDbBlockTableRecordIterator* pIter = NULL;

AcRes = pRec->newIterator(pIter);

if(!pIter)

{

pRec->close();

delete pIter;

acutPrintf(_T("\n newIterator -> %s"),::acadErrorStatusText(AcRes));

return;

}

AcDbEntity* pEnt = NULL;

for(pIter->start(); !pIter->done(); pIter->step())

{

AcRes = pIter->getEntity(pEnt,AcDb::kForRead);

if(AcRes != Acad::eOk)

{

delete pIter;

pRec->close();

acutPrintf(_T("\ngetEntity -> %s"),::acadErrorStatusText(AcRes));

return;

}

if(pEnt->isKindOf(AcDbHatch::desc()))

{

if(((AcDbHatch*)pEnt)->associative()==true)

{

pEnt->close();

pEnt=NULL;

}

}

if(pEnt)

{

AcRes = pEnt->upgradeOpen();

if(AcRes==Acad::eOk)

{

AcRes = pEnt->transformBy(mat);

if(AcRes!=Acad::eOk)

acutPrintf(_T("\ntransformBy -> %s"),::acadErrorStatusText(AcRes));

AcRes = pEnt->close();

}else

acutPrintf(_T("\nupgradeOpen -> %s"),::acadErrorStatusText(AcRes));

pEnt->close();

}

 

}

pRec->close();

delete pIter;

AcRes = acDocManager->unlockDocument(curDoc());

acutPrintf(_T("\nAcRes = %s"),::acadErrorStatusText(AcRes));

}

Message 7 of 12
owenwengerd
in reply to: igor.ivanov

It sounds like my initial hunch was correct, that it's not possible to update a hatch when the document is not open in the editor. The only solution I can suggest is to open the drawing in the editor instead.

--
Owen Wengerd
ManuSoft
Message 8 of 12
igor.ivanov
in reply to: igor.ivanov

Hmm, but it is open in the editor trough COM:

 

acadDoc->Open(...)

 

I use it becouse many other thinks can not be done if dwg is not open in editor, otherwise I probably have used AcDbDatabase::readDwgFile().

 

Is there any mechanism I can Force Hatch to be updated?

Message 9 of 12
owenwengerd
in reply to: igor.ivanov

The only other ideas I have at the moment are to make the document active before operating on it; or maybe open it via document manager instead of using COM.

--
Owen Wengerd
ManuSoft
Message 10 of 12

I agree with Owen. Also I think that this document have to be not only active but also current with help of acDocManager->setCurDocument(pDoc, AcAp::kWrite)

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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
Expert Elite Member

Message 11 of 12
igor.ivanov
in reply to: igor.ivanov

Found solution by myself for this case, when dwg is opened trough COM just send

ACRX_CMD_MODAL command to it using COM pointer to doc:

 

acadDoc->SendCommand(_bstr_t(_T("MyCommandLocal ")));

 

In this command lock document and iterate trough entities and trnsform only plines for witch hatch is associative(not hatches itself) and evrything works as suppose to work.

 

Thanks for help anyway.

 

Igor

Message 12 of 12
Anonymous
in reply to: igor.ivanov

Hi !

Sorry to interfere, but I happend to have the exact same problem, even though I do not use ObjectARX but pure Autocad VBA (we are using Autodesk Map 3D 2009).

Is it possible that I am running into the same issue using VBA ?

 

What I do is very simple though : Open document through VBA, thaw all layers, Close&Save. Upon opening the drawing, an accadoc.lsp file is automatically executed, and it retrieves and reassociates hatch boundaries for non assiociative hatches.

If I opened the saved drawing, some hatchs do not follow their boundaries. Moving any point of the boundary is enough for the hatch to be correctly redrawn, but nothing else does the trick (regen does not help for instance).

 

So could this issue be applicable in my case, and if yes, what could be the workaround ? There are no suck thing as application or session context in VBA, as far as I know.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost