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

About readDwgFile() and saveAs() functions.

9 REPLIES 9
Reply
Message 1 of 10
PrashantSL
995 Views, 9 Replies

About readDwgFile() and saveAs() functions.

Hi Group,

I have few questions, it would be great if anyone has any inputs on it. I am struggling to get it cleared...

1. AcDbDatabase:saveAs:

The ObjectARX document says:
"Before calling this function, set the current database as the working database. Otherwise, failures may occur."

Does this indicate that the AcDbDatabase object on which we are calling this method should be set as current working database and after save the old database should be restored?
e.g.
//Set m_pDatabase as working one and restore old one after save.
AcDbDatabase* pOldDb = NULL;
pOldDb = acdbHostApplicationServices()->workingDatabase();
acdbHostApplicationServices()->setWorkingDatabase(m_pDatabase);
m_pDatabase->saveAs();
acdbHostApplicationServices()->setWorkingDatabase(pOldDb);

2. Is it necessary to lock/set current document for the drawing for which saveAs is getting called and
after save unlock/restore earlier document as current?

3. readDwgFile().
It is mentioned that This function should only be used on a newly created AcDbDatabase.
Now we can create AcDbDatabase as
AcDbDatabase(bool buildDefaultDrawing = true, bool noDocument = false);
If noDocument == true, then the newly created database will not be associated with the current document; otherwise it will. What does this statment indicate?

Now suppose I have a drawing A which contains external reference to drawing B. Drawing is A is currently opened in ACAD.
I want to open and updated XREFed drawing B. So I do it like:
///////////////////////////////////////////////////////
AcDbDatabase* pDatabase = new AcDbDatabase(true, true);
pDatabase->readDwgFile("Full path of drawing B");
...
//update some attributes of drawing B
...
pDatabase->saveAs("Full path of drawing B");
///////////////////////////////////////////////////////
Is this correct way of editing xrefed drawing information?
As readDwgFile does not open any document as such in ACAD so I can not obtain the AcApDocument pointer
by using : AcApDocument* pDocRead = acDocManager->document(pDatabase); So I can not lock/unlock the file opened by readDwgFile.

If there is any problem in explaining the problem from my side, please correct me.
Eagerly waiting for your expert replies....

-Prashant
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: PrashantSL

The formatting of your message is lost in my newsreader, so I may miss
some things.

1) Exactly.
2) Only if the database is open in the editor (i.e. it is owned by an
AcApDocument).
3) "associated with a document" means it gets default values from the
document, nothing more as far as I know.
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>
Message 3 of 10
PrashantSL
in reply to: PrashantSL

Hi Owen,



Thanks a lot for your answers.

I have some new doubts like:



2) Only if the database is open in the editor (i.e. it is owned by an

AcApDocument).



So, as per this if I open a drawing with readDwgFile and it is not associated with any document already opened in ACAD and I do some updates on that drawing(read with readDwgFile call) and then save it back as saveAs then it should work fine.



3) "associated with a document" means it gets default values from the

document, nothing more as far as I know.



What kind of default values are taken? So if we associate the drawing being read with readDwgFile with currently opened drawing then can we lock/unlock that document in order to perform some operations on our file read from readDwgFile.



Owen, can u please look the remaining part of question 3 in my post? Its about reading and updating an xref-ed drawing, is it correct way of doing that?



Once again saying thank you very much!

Have a nice day!



Regards,

-Prashant
Message 4 of 10
Anonymous
in reply to: PrashantSL

Actually, we get certain values from the current document whether or not the
second argument is true. The main thing is that if the second argument is
true, then the database gets its own undo controller and transaction
manager.

"Owen Wengerd" wrote in message
news:6142939@discussion.autodesk.com...
The formatting of your message is lost in my newsreader, so I may miss
some things.

1) Exactly.
2) Only if the database is open in the editor (i.e. it is owned by an
AcApDocument).
3) "associated with a document" means it gets default values from the
document, nothing more as far as I know.
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>
Message 5 of 10
Anonymous
in reply to: PrashantSL

Art:

Thanks. Someone should document that... 🙂
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>


"Art Cooney" wrote in message
news:6143243@discussion.autodesk.com...
Actually, we get certain values from the current document whether or not the
second argument is true. The main thing is that if the second argument is
true, then the database gets its own undo controller and transaction
manager.

[...]
Message 6 of 10
Anonymous
in reply to: PrashantSL

It sounds like you're on the right track Prashant. 🙂
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>
Message 7 of 10
PrashantSL
in reply to: PrashantSL

Hi Owen and Art,

Thanks a lot for your kind help and replies.

I am facing a situation in which I try to change the names of the drawing files.
Details are like:
A X
| ----rename to -> |
-----B ------Y
I am having drawing A open in ACAD and this drawing has another drawing B added as external reference.
Now I search for opened drawing and found A is current drawing in which I am interested, I use AcDbDatabase of this drawing and rename it with saveAs() call to another name say X.
Now when I try to search for opened drawing "B", which is external referenced in A(now name changed to X). I don't find it currently opened. So I create a new AcDbDatabase() object(by using AcDbDatabase(Adesk::kFalse,Adesk::kTrue)). Then I read drawing B in this database by using readDwgFile call.
But when I save this drawing B to "Y" by using saveAs() then its renaming the already renamed drawing X and not the B.
Trying to figure out whats going wrong...

I hope that I am not too confusing...:)

Thanks once again!
-Prashant
Message 8 of 10
PrashantSL
in reply to: PrashantSL

Correcting statements in earlier post:
"
But when I save this drawing B to "Y" by using saveAs() then its renaming the already renamed drawing X and not the B.
Trying to figure out whats going wrong...
"
Whats happening is when I saveAs component B to Y it is getting renamed. But when I use acDocManager->newAcApDocumentIterator() to iterate through opened drawing I can find only Y and not X which is parent of Y.

So simplifying question: Is it the case that file which is not currently opened in ACAD & opened via readDwgFile call & then saved to a different name by using saveAs call, actually opens it in ACAD?

-Prashant
Message 9 of 10
Anonymous
in reply to: PrashantSL

Prashant:

I'm not surprised that this is problematic. I don't have any experience
opening and saving files this way, so hopefully someone else can help. The
only thought I have is that if you're just renaming files, why not just,
well, rename the file via the OS?
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>
Message 10 of 10
PrashantSL
in reply to: PrashantSL

Hi Owen;

I know the situation that I explained is a bit chaotic!
I will surely will try to separate out the renaming part...I think it will resolve some problem.
Thanks a lot for your suggestion!
About problem that I am facing...
Details:
I created(edited) a sample application from exiting ObjectARX Sample sample\com\AsdkMfcComSamp_dg.
I registered commands with ACRX_CMD_SESSION. Because I need to show some .NET GUIs.
In the command handler of one of the menu I put code as below:
I loaded the ARX generated by this sample in ACAD and opened drawing "A" which has drawing B added as Xref.
Then I read the drawing B(which is not currently opened in ACAD). Now If I set database object pLocalDb as working database then
currently opened drawing A is getting renamed(strange!!!). Otherway its working fine...

If I don't set the working database as pLocalDb then it works fine and I get the drawing B renamed copy as C.
/////CODE STARTS////
Acad::ErrorStatus eErrorStatus = Acad::eOk;
AcDbDatabase * pOld = acdbHostApplicationServices()->workingDatabase();

AcDbDatabase *pLocalDb = new AcDbDatabase(Adesk::kFalse,Adesk::kTrue);
if(pLocalDb)
{

eErrorStatus = pLocalDb->readDwgFile(_T("C:\\temp\\B.dwg"));
//rename is working fine for component which is not currently opened, if pLocalDb is not set as current working database.
//acdbHostApplicationServices()->setWorkingDatabase(pLocalDb);

if(eErrorStatus== Acad::eOk)
{
eErrorStatus = pLocalDb->saveAs(_T("C:\\temp\\C.dwg"));
}

//acdbHostApplicationServices()->setWorkingDatabase(pOld);
}
///CODE ENDS////
As per documentation "the database on which saveAs is called should be made working database" but in this case its causing problem.

If anyone has any clue please guide!

Thanks a lot for all your help!

-Prashant

Edited by: PrashantSL on Mar 18, 2009 3:10 PM Edited by: PrashantSL on Mar 18, 2009 3:13 PM

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

Post to forums  

Autodesk Design & Make Report

”Boost