Automate create Drawings

Hy,

I want to create a Plugin which do create Drawings (from DrawingTab) automatically like:

1: Load Drawing template
2: Load different views from current opened Layout
3: Define position of views
4: Save a dxf and a PDF

But I can’t find the API for this… :face_with_spiral_eyes:

Thx & Regards
Feature

1 Like

Drawings are mostly UI side stuff, so I think you’ll need to look into UX.Shared, and UX.Shared.Infrastructure dlls.
There are some basics like IDrawingContext, and then a bunch of commands that are available to import as IActionItems

1 Like

ExportDrawings

Tried it out, it should be possible, but haven’t figure out how to create pdf and dwg automatically.

IApplication app;
IDrawingViewGenerationAction projectAction;
IImportDrawingTemplateAction templateAction;
ICommandRegistry registry;

public override void Execute()
{
    templateAction.StartAction();
    var a0 = PathUtility.BaseDirectory + "SrcTemplates\\Drawings\\DrawingTemplateA0.vcm";
    foreach (var item in templateAction.ActionProperties)
    {
        if (item.Name == "File")
        {
            item.Value = a0;
        }
    }
    templateAction.ApplyAction();
  
    var minCorner = app.DrawingWorld.BoundBox.MinCorner;
    var maxCorner = app.DrawingWorld.BoundBox.MaxCorner;
    var intervalX = (maxCorner.X - minCorner.X) * 0.8 / 3.0;
    var intervalY = (maxCorner.Y - minCorner.Y) * 0.8 / 2.0;
    var borderX = (maxCorner.X - minCorner.X) * 0.15;
    var borderY = (maxCorner.Y - minCorner.Y) * 0.3;
  
    // Top
    projectAction.CreateView(DrawingViewPoints.Top);
    var top = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
    top.Scale = "1:3";
    var topMatrix = new Matrix();
    topMatrix.Px = minCorner.X + borderX + intervalX * 0;
    topMatrix.Py = minCorner.Y + borderY + intervalY;
    top.TransformationInWorld = topMatrix;
  
    // Left
    projectAction.CreateView(DrawingViewPoints.Left);
    var left = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
    left.Scale = "1:3";
    var leftMatrix = new Matrix();
    leftMatrix.Px = minCorner.X + borderX + intervalX * 1;
    leftMatrix.Py = minCorner.Y + borderY + intervalY;
    left.TransformationInWorld = leftMatrix;
  
    // Front
    projectAction.CreateView(DrawingViewPoints.Front);
    var front = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
    front.Scale = "1:3";
    var frontMatrix = new Matrix();
    frontMatrix.Px = minCorner.X + borderX + intervalX * 2;
    frontMatrix.Py = minCorner.Y + borderY + intervalY;
    front.TransformationInWorld = frontMatrix;
  
    // Bottom
    projectAction.CreateView(DrawingViewPoints.Down);
    var bottom = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
    bottom.Scale = "1:3";
    var bottomMatrix = new Matrix();
    bottomMatrix.Px = minCorner.X + borderX + intervalX * 0;
    bottomMatrix.Py = minCorner.Y + borderY;
    bottom.TransformationInWorld = bottomMatrix;
  
    // Right
    projectAction.CreateView(DrawingViewPoints.Right);
    var right = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
    right.Scale = "1:3";
    var rightMatrix = new Matrix();
    rightMatrix.Px = minCorner.X + borderX + intervalX * 1;
    rightMatrix.Py = minCorner.Y + borderY;
    right.TransformationInWorld = rightMatrix;
  
    // Back
    projectAction.CreateView(DrawingViewPoints.Back);
    var back = (IDrawingView)app.DrawingWorld.LayoutItems.Last();
    back.Scale = "1:3";
    var backMatrix = new Matrix();
    backMatrix.Px = minCorner.X + borderX + intervalX * 2;
    backMatrix.Py = minCorner.Y + borderY;
    back.TransformationInWorld = backMatrix;
  
    registry.ExecuteAction("ExportToVectorDrawing2D", true, true);
}
3 Likes

@idkfa Thank you! :slight_smile:

@TSy any idea for the saving stuff as dxf and pdf?

Hy,

is there somewhere a list with all possible commands like:

Thx & Regards
Feature

You can get all registered actions from ICommandRegistry.Actions and then get the IActionItem.Id from each.

1 Like

Hy @TSy or everyone who can help,

how to select pdf or dxf and trigger export?

Regards
Feature

Try casting the IActionItem with id “ExportToVectorDrawing2D” to IExportToVectorDrawingCommand and then using the ApplyAction method from that interface.

Hy @TSy ,

I really would try this but my VC 4.7 Premium does not know these interface!?
image

but it should be public:

Thx & Regards
Feature

You need to add reference to the UX.Shared.Infrastructure dll. Notice how the help page says
Assembly: UX.Shared.Infrastructure

2 Likes

Hy again,

and is there a way to get the dialogService which opens after successfully realize your magic, for finally save the file by keeping the full automatic? → No user interaction…

The help is helping not so much:

Thx & Regards
Feature

Hy,

it looks like nobody from VC -Stuff has ever thought about that some people would automate that drawing stuff… :confused:

  • The method “GetSupportedFormats” sometime throw nullReferenceException.

  • In Helpfile alot of important stuff is missing

  • How should I get the FileSaveDialog instead of show it to user?

Why is that so that a lot of VC Framework is awesome and some parts are so tedious!?

Feature

1 Like

I’d say that really only the Create3d.Shared is the real public .NET API of VC. Everything else is a bit hit or miss.

Why there is no proper API for automating drawing generation and saving? Probably they just haven’t got enough requests for such use case from customers at VC’s support and sales. :man_shrugging:

Hy @TSy ,

that’s really bad news, we try to implement VC in our company in different departments and I have to check the technical feasibility… → So this project fail at the last step by checking the first point, cause of missing API! :confused:

But I will thank you and @idkfa, for getting me fast to this ugly limitation!

VC will probably miss some license sales because of this!

Regards
Feature

1 Like

Please contact VC technical support. They might figure out some workaround for you.

I will…

Thx & Regards
Feature

I have read it, may support will me also offer the working api… :wink:

Regards
Feature

1 Like

Hy @idkfa,

my last open point (without the missing possibilty to save… :face_vomiting: ) is to create one isometric view like (I do it manual):

For this I first set vcCamera to the the view i I need (works), and use a bit modified code from you, but VC wont take over this… → May you have an idea for this?

Thx & Regards
Feature

It seems that DrawingViewPoints.Current is not working, recommend to contact support.

Ok, I will add this also to my official request… :frowning:

Thx & Regards
Feature