RealDWG: Layout Creation Problems

RealDWG: Layout Creation Problems

mdeabreu
Participant Participant
1,265 Views
9 Replies
Message 1 of 10

RealDWG: Layout Creation Problems

mdeabreu
Participant
Participant

Hello,

 

I'm having some troubles when attempting to programmatically create a layout in a DWG file using RealDWG. I can create a layout using the AcDbLayoutManager, however when I add entities to the associated block table record, save the DWG file, and open it in Map 3D 2015 the "paper" in the layout has shrunk to surround the entities rather than staying the default size.

 

If I don't add any entities to the block table record, and again save and open the file in Map 3D the "paper" is a larger like I would like.

 

I wouldn't mind if the "paper" shrank but the main problem is that I can't seem to programmatically change the size of it. I can see in the documentation that I should be able to change the size, origin, and margin properties of the layout by using a AcDbPlotSettingsValidator object but I can never seem to get access to that object.

 

Everytime I attempt to get the object using the following command:

 

AcDbPlotSettingsValidator* pPSV = acdbHostApplicationServices()->plotSettingsValidator()

 

I am returned a null pointer.

 

Are there any specific merge modules, DLLs, or libs that we need in order to get a valid pointer?

 

Thank you for any help,

Matthew DeAbreu

0 Likes
1,266 Views
9 Replies
Replies (9)
Message 2 of 10

artc2
Autodesk
Autodesk

You can't get an AcDbPlotSettingsValidator in a RealDWG app.  The AcDbPlotSettingsValidator class is an abstract base class and the only concrete implementation of it is in accore.dll which is not part of RealDWG.

 

Even though AcDbPlotSettingsValidator is an abstract class, there are implementations for its methods, so you could try deriving your own class from AcDbPlotSettingsValidator and implement the methods in your class to simply call the base class methods. I'm not sure it will do what you need because a RealDWG app doesn't have access to any plotter information as AutoCAD does, so the default implementations of the AcDbPlotSettingsValdator methods may not have enough information to work.  This is not something that we (Autodesk) test, but you could try it and see if it works.

0 Likes
Message 3 of 10

mdeabreu
Participant
Participant

Thank you for the suggestion, unfortunately I've had little success. Do you know of any other way to modify the "paper" from a RealDWG application? Any help would be greatly appreciated.

 

To help give a sense of what I am trying to accomplish I have attached two images. The first (original.png) shows a layout containing a viewport, a table, and an mtext.

 

The second image (output.png) shows what my program outputs, as you can see it is able to recreate the viewport, table, and mtext; however the layout is not the correct size. That is what I am attempting to change.

 

Thank you very much,

Matthew DeAbreu

0 Likes
Message 4 of 10

Balaji_Ram
Alumni
Alumni

Hi Matthew,

 

Would it be possible to create a drawing using AutoCAD with its layout initialized (switching to the layouts before saving) and then use

that drawing as a template ?

 

Your RealDWG application can read the drawing file when it needs to create one, modify it by adding entities etc and then save it as another file.

 

I am not sure if this workaround will help, but you can give it a try.

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 10

mdeabreu
Participant
Participant

That is actually what we are currently doing, I was hoping to expand the capabilities of our application to create the layouts ourselves which would give more control to our users.

 

Thank you for the suggestion though,

Matthew DeAbreu

0 Likes
Message 6 of 10

mdeabreu
Participant
Participant

Here is another example of the problems I am attempting to overcome, any help would be greatly appreciated.

 

I create a new layout and add a polyline to the newly created Block Table Record. If I open the AcDbLayout object and get its limits I see it has a limMin of (0,0) and a limMax of (12,9). This layout and polyline should look roughly like this:

 

outGood.png

 

Unfortunately when I save and close the database the "paper" in the layout shrinks down to the size of the polygon (the polygon stays in the same location and is the same size) as you can see here:

 

outBad.png

 

If I am unable to set the properties of the layout is there any way for me to prevent this from happening?

 

Any help is greatly appreciated

Matthew

0 Likes
Message 7 of 10

Balaji_Ram
Alumni
Alumni

Hi Matthew,

 

Can you please share a sample project for me to reproduce the issues you are having ?

Also, which version of RealDWG are you using ?

 

Please do not include any information that you consider confidential.

 

Thanks

 

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 10

mdeabreu
Participant
Participant

Hi Balaji,

 

We are using RealDWG 2015, here is a rough piece of code to show you approximately what we are doing.

 

Acad::ErrorStatus acadErr;
AcDbDatabase* pDb = new AcDbDatabase(true);
acdbHostApplicationServices()->setWorkingDatabase(pDb);

AcDbLayoutManager* pLayoutManager = acdbHostApplicationServices()->layoutManager();

AcDbObjectId layoutId, BTRId;

// Create a new layout, we will not write anything into this and it will be a
// decently large size roughly (0,0) to (11,8.5)
acadErr = pLayoutManager->createLayout(L"goodLayout", layoutId, BTRId);
acadErr = pLayoutManager->setCurrentLayoutId(layoutId);

// Create another new layout, we will write two points into this layout and when
// we close and save the database the "paper" will shrink down to the locations
// of the points
acadErr = pLayoutManager->createLayout(L"badLayout", layoutId, BTRId);
acadErr = pLayoutManager->setCurrentLayoutId(layoutId);

// Open the layouts block table record so we can add entities
AcDbBlockTableRecord* pBTR = NULL;
acadErr = acdbOpenObject(pBTR, BTRId, AcDb::kForWrite);

// Create our points to add to the layout
AcDbPoint* pPoint1 = new AcDbPoint;
AcDbPoint* pPoint2 = new AcDbPoint;
acadErr = pBTR->appendAcDbEntity(pPoint1);
acadErr = pBTR->appendAcDbEntity(pPoint2);

// Set their positions
acadErr = pPoint1->setPosition(AcGePoint3d(3.0, 7.0, 0.0));
acadErr = pPoint2->setPosition(AcGePoint3d(4.0, 8.0, 0.0));

// Close everything
pPoint1->close();
pPoint2->close();
pBTR->close();

acadErr = pDb->saveAs(L"C:\\temp\\out.dwg", false, AcDb::kDHL_1027, NULL);
delete pDb;
acdbHostApplicationServices()->setWorkingDatabase(NULL);

 

I've also attached the resulting DWG file; as you can see like I mentioned in the comments of the sample code the goodLayout goes from (0,0) to (11,8.5) whereas the badLayout has shrunk down to be just a little bit larger than the location of the two points. This always happens regardless of what types of entities are written into the layouts block table record.

 

Being able to prevent this from happening would be very useful.

 

Thank you for any help,
Matthew

0 Likes
Message 9 of 10

owenwengerd
Advisor
Advisor

Matthew, if you're serious about getting this resolved, why not provide a buildable project as Balaji asked? Making his job more difficult will only delay resolution of the problem.

--
Owen Wengerd
ManuSoft
0 Likes
Message 10 of 10

mdeabreu
Participant
Participant

Hello,

 

I've attached a zip file with a sample application that should compile and show the correct results. Inside the zip you will find a folder "LayoutSample" place this in the "Samples" folder found in the install directory of the RealDWG SDK so the path to the project is "<realdwginstall>\Samples\LayoutSample\creatent.vcxproj".

 

You should now be able to compile it (I'm using Visual Studio 2013) and building in x86. It will create the executable in the root of the install directory, from there you can run the executable and you should have an out.dwg file created in the same directory. Opening this up with an AutoCAD application (I'm using Map3D 2015) you should see the two layout tabs and the difference between them.

 

Please let me know if you would like any more information or are having problems getting this to work.

 

Thank you,

Matthew

0 Likes