2

I'm trying to plot using "Window" as PlotType in AutoCad. This is the code:

ViewBorder border = new ViewBorder();

Point3d first = new Point3d(border.Width, 0, 0);
Point3d second = new Point3d(border.Height, 0, 0);

Extents2d window = TransformCoordinates(first, second);

psv.SetPlotWindowArea(ps, window);

psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);

The TransformCoordinates method only receives two Point3d arguments (x and y) and transform them from UCS to DCS coordinates returning a Extents2d. I don't want to ask user to select points(There is some examples using this on the internet). The only thing that i want is that "first" and "second" variables becames a Point3d. The first must be the top left corner from the drawing in the ModelSpace and the second must be the bottom right corner in the model space drawing also. How could i do that? Is there any king of configuration in PlotType (Or other thing) that could manage all of this for me, i.e., not asking user to selected corners and select the whole drawing in model space for me?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Flávio Schuindt
  • 403
  • 1
  • 7
  • 15
  • Are you saying you'd need to grab the upper left/bottom right corners of the actual lines of a square for instance or the corners of the active window? – ChiefTwoPencils Jan 17 '13 at 22:30
  • When you select "window" in Plot type in Plot menu inside AutoCad, it gives to you an option to select two points. In my case, i need to select whole drawing in model space (yes, if you try to do this in autocad you can selwct drawing with a square), but i'm trying to do this without prompting user and allowing him to input the points! – Flávio Schuindt Jan 18 '13 at 04:04

2 Answers2

1

My experience is not with C# and AutoCad. I was trained on AutoLISP. But knowing how AC works I'd say your best bet is to take control over the command prompt as documented here.

By what you've said I'm assuming you'd like to print what ever is in model space; is that correct?

Well when you're in PaperSpace you can switch to ModelSpace by typing ._MSPACE on the command line. This will enable you to work in MSpace through a hole in PSpace - so to speak. So, if the layout in PSpace is not showing the entire contents of MSpace you can switch to MSpace and enter z or type zoom on the command line. You'll then have all the options any user would inside model space utilizing the zoom tool (All/Center/Dynamic...). All would probably be the best bet.

So when the user clicks your button or enters your alias you can automate the entire process. You can switch to MSpace-> zoom all -> plot -> layout (what to plot).

Update:

I realize now that my link did not take you to the specific topic I intended.(?)
Here is a snippet of what I think you should try -

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

[CommandMethod("selectEntireAutoCadDrawing")]
public static void selectEntireAutoCadDrawing()
{
  //This sets up your doc. Not sure if this is the way you're doing it.
  //I imagine you'd probably pass the doc into the method.
  Document yourACDoc = Application.DocumentManager.MdiActiveDocument;

  //When your plug-in is invoked the first thing I'd do is make sure they're
  //in PaperSpace
  yourACDoc.SendStringToExecute("tilemode 0 ");

  //Next enable ModelSpace through PaperSpace.
  yourACDoc.SendStringToExecute("_mspace ");

  //Now we zoom to the extents of the drawing.
  //Not sure about the bools at the end. The AC documentation has it there for a
  //zoom all example but AC doesn't ask any further questions after selecting the 
  //all or extents zoom types and doesn't elaborate on it?
  yourACDoc.SendStringToExecute("._zoom _extents "/*, true, false, false*/);

  //Head back to PaperSpace
  yourACDoc.SendStringToExecute("_pspace ");
}

At this point your drawing should all be there in PaperSpace. Now just continue with the rest of your execution.

AC command line requires the space bar, return, or if set up correctly a mouse click to execute any command. That is why there are spaces between some parameters. It is essential to do it this way or they will be interpreted as unknown commands.

You might have to play around with it a bit, look at the API reference, or use a different zoom type. Zooms can get tricky if you have multiple users with different styles especially in a loosely managed shop. If this will be implemented in an environment where people are aware of it's limitations it should be fine.

Also - it'd be good to make yourself familiar with AC. You can use the command line as a debugger for it shows a list of all the commands entered and any error messages. It will also allow you to design in advance. Just enter the commands in AC make notes of the order and purpose of the prompts and code accordingly. There is also a way to record actions into a macro which is the route many with no programming knowledge take.

Good luck~

ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75
  • I don't know much how to use AutoCAD like a user. I have to automate a task that is done over and over by users. The task itself is: Open several files, plot each one to pdf. I can, by now, open several files and plot each of them to pdf files. But there is some configuration in Plot that i want to automate too. These configurations envolves on the Plot configuration box to select Window and select the whole drawing on the Model Space (I think that it can de bone in Paper Space also). What i want is to define a PlotWindowArea automatically! – Flávio Schuindt Jan 18 '13 at 11:40
0

Try this.

using Autodesk.AutoCAD.ApplicationServices;
using App = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

Document curDoc = App.DocumentManager.MdiActiveDocument;
Extents3d allEntsExtents = new Extents3d();
using (Transaction tr = curDoc.TransactionManager.StartTransaction())
{
    BlockTable bt = tr.GetObject(curDoc.Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
    BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead, false) as BlockTableRecord;
    allEntsExtents.AddBlockExtents(btr);
    tr.Commit();
}
Plane plane = new Plane();
Extents2d window = new Extents2d(
    allEntsExtents.MinPoint.Convert2d(plane),
    allEntsExtents.MaxPoint.Convert2d(plane));
Chuck Wilbur
  • 2,510
  • 3
  • 26
  • 35