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

Read mode works fine, but write mode produces a lock violation.

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
575 Views, 4 Replies

Read mode works fine, but write mode produces a lock violation.

This is starting to make my brain feel like oatmeal...

Is there anything in the routine below that would cause a lock error when I try to open one of the items in the selectedItems vector in write mode? I can open them in read mode and it works fine, but write mode returns a lock violation.

I create the vector immediately before this call and try to open the selected entities immediately after. Nothing is opened before this routine.

{code}
bool FilterManager::getAllObjectsOfTypeInDrawing( CStringW objectType, std::vector& selectedItems )
{
AcDbDatabase* pDbase = activeDrawing();
if (pDbase == NULL) {
return false;
}

struct resbuf *entmask = NULL;

if( objectType == L"Closed 3d Polyline" ) {
entmask = acutBuildList(
-4, L" RTDXF0, L"POLYLINE",
70, 9,
-4, L"and>",
0);
} else if( objectType == L"Closed 2d Polyline" ) {
entmask = acutBuildList(
-4, L" -4, L" RTDXF0, L"POLYLINE",
RTDXF0, L"LWPOLYLINE",
-4, L"or>",
70, 1,
-4, L"and>",
0);
} else if( objectType == L"Open 3d Polyline" ) {
entmask = acutBuildList(
-4, L" 70, 8,
RTDXF0, L"POLYLINE",
-4, L"and>",
0);
} else if( objectType == L"Open 2d Polyline" ) {
entmask = acutBuildList(
-4, L" -4, L" RTDXF0, L"POLYLINE",
RTDXF0, L"LWPOLYLINE",
-4, L"or>",
-4, L" 70, 1,
-4, L"not>",
-4, L" 70, 9,
-4, L"not>",
-4, L"and>",
0);
} else if( objectType == L"Ellipse" ) {
entmask = acutBuildList(
RTDXF0, L"ELLIPSE",
0);
} else if( objectType == L"Circle" ) {
entmask = acutBuildList(
RTDXF0, L"CIRCLE",
0);
} else if( objectType == L"Line" ) {
entmask = acutBuildList(
RTDXF0, L"LINE",
0);
} else if( objectType == L"Arc" ) {
entmask = acutBuildList(
RTDXF0, L"ARC",
0);
} else if( objectType == L"Spline" ) {
entmask = acutBuildList(
RTDXF0, L"SPLINE",
0);
} else if( objectType == L"Text" ) {
entmask = acutBuildList(
-4, L" RTDXF0, L"TEXT",
RTDXF0, L"MTEXT",
-4, L"or>",
0);
} else if( objectType == L"Point" ) {
entmask = acutBuildList(
RTDXF0, L"POINT",
0);
} else if( objectType == L"Block" ) {
entmask = constructBlockMask( );
} else {
return false;
}

int respondResult;
ads_name selectionSet;

// get the selections from the user
respondResult = acedSSGet(L"X", NULL , NULL, entmask, selectionSet);
if ( respondResult != RTNORM) {
goto ALLDONE;
}

long numEntities;
long i;
if ( acedSSLength(selectionSet,&numEntities) != RTNORM ) {
goto ALLDONE;
}
ads_name entityName;

// add all the entities to the object array
for(i = 0; i < numEntities; ++i) {
AcDbObjectId objectId;
acedSSName(selectionSet, i, entityName);
acdbGetObjectId(objectId, entityName);
selectedItems.push_back(objectId);
}

acedSSFree(selectionSet);

if ( respondResult != RTNORM) {
goto ALLDONE;
}

ALLDONE:

if ( entmask != NULL ){
acutRelRb(entmask);
entmask = NULL;
}

return ! selectedItems.empty();
}
{code}
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous


It sounds like your code is being executed in a
situation where AutoCAD hasn't automatically locked the document on which you
are operating.  So, you'll have to lock/unlock it yourself.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
This
is starting to make my brain feel like oatmeal... Is there anything in the
routine below that would cause a lock error when I try to open one of the
items in the selectedItems vector in write mode? I can open them in read mode
and it works fine, but write mode returns a lock violation. I create the
vector immediately before this call and try to open the selected entities
immediately after. Nothing is opened before this routine. {code} bool
FilterManager::getAllObjectsOfTypeInDrawing( CStringW objectType,
std::vector& selectedItems ) { AcDbDatabase* pDbase =
activeDrawing(); if (pDbase == NULL) { return false; } struct resbuf *entmask
= NULL; if( objectType == L"Closed 3d Polyline" ) { entmask = acutBuildList(
-4, L"", 0); } else if(
objectType == L"Closed 2d Polyline" ) { entmask = acutBuildList( -4, L" -4, L?POLYLINE?, RTDXF0, L?or L?LWPOLYLINE?, L?", 70, 1, -4, L"and>",
0); } else if( objectType == L"Open 3d Polyline" ) { entmask = acutBuildList(
-4, L"", 0); } else if(
objectType == L"Open 2d Polyline" ) { entmask = acutBuildList( -4, L" -4, L?POLYLINE?, RTDXF0, L?or L?LWPOLYLINE?, L?", -4, L" L?not 1,>", -4, L"", -4, L"and>", 0); } else if(
objectType == L"Ellipse" ) { entmask = acutBuildList( RTDXF0, L"ELLIPSE", 0);
} else if( objectType == L"Circle" ) { entmask = acutBuildList( RTDXF0,
L"CIRCLE", 0); } else if( objectType == L"Line" ) { entmask = acutBuildList(
RTDXF0, L"LINE", 0); } else if( objectType == L"Arc" ) { entmask =
acutBuildList( RTDXF0, L"ARC", 0); } else if( objectType == L"Spline" ) {
entmask = acutBuildList( RTDXF0, L"SPLINE", 0); } else if( objectType ==
L"Text" ) { entmask = acutBuildList( -4, L" L?TEXT?,>", 0); } else if( objectType == L"Point" ) { entmask = acutBuildList(
RTDXF0, L"POINT", 0); } else if( objectType == L"Block" ) { entmask =
constructBlockMask( ); } else { return false; } int respondResult; ads_name
selectionSet; // get the selections from the user respondResult =
acedSSGet(L"X", NULL , NULL, entmask, selectionSet); if ( respondResult !=
RTNORM) { goto ALLDONE; } long numEntities; long i; if (
acedSSLength(selectionSet,&numEntities) != RTNORM ) { goto ALLDONE; }
ads_name entityName; // add all the entities to the object array for(i = 0; i
< numEntities; ++i) { AcDbObjectId objectId; acedSSName(selectionSet, i,
entityName); acdbGetObjectId(objectId, entityName);
selectedItems.push_back(objectId); } acedSSFree(selectionSet); if (
respondResult != RTNORM) { goto ALLDONE; } ALLDONE: if ( entmask != NULL ){
acutRelRb(entmask); entmask = NULL; } return ! selectedItems.empty(); }
{code}
Message 3 of 5
Anonymous
in reply to: Anonymous

100% correct. I locked the document before my code ran and unlocked it after and it works perfectly!

Thank you!

My brain feels a lot less like oatmeal today!
Message 4 of 5
Anonymous
in reply to: Anonymous

Hi. I am experiencing the same thing. How do you unlocked the document?

Message 5 of 5
tbrammer
in reply to: Anonymous

The easiest way is to simply create an AcAxDocLock object in the code block that needs locking:

 

 

AcAxDocLock lock;
// your code

 

 

The AcAxDocLock constrctor will lock the current document and its destructor will unlock it again. So your current document is locked within the scope of the AcAxDocLock object.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

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

Post to forums  

Technology Administrators