Jump to content

Pick viewport and draw grid line orthoview plant 3d


Recommended Posts

Good Night everyone, i am new on this C# world, i need to do run in Auto cad Plant 3D the following. 


1- i will make 3D model containing navite grid line from struct grid. 


2- I Will generate view ports for Orthoviews


3- Now I want to pick the view port and my C# code recognizes the gridline and draw grid bubbles and position them in my drawing.


I've make the code but it says a lot of errors, i get no clue what is going on. does anybody can help please? 


using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.ProcessPower.PnP3dObjects;

public void DrawGridLine()
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;
    Editor acEd = acDoc.Editor;

    // Select viewport
    PromptEntityOptions peo = new PromptEntityOptions("\nSelect viewport: ");
    peo.SetRejectMessage("\nPlease select a valid viewport.");
    peo.AddAllowedClass(typeof(Viewport), true);
    PromptEntityResult per = acEd.GetEntity(peo);

    if (per.Status != PromptStatus.OK)
        acEd.WriteMessage("\nError selecting viewport.");

    Viewport vp = (Viewport)per.ObjectId.GetObject(OpenMode.ForWrite);

    // Draw grid line
    Gridstruct gs = new Gridstruct();
    gs.LayerName = "GRID";
    gs.GridColor = Color.FromColorIndex(ColorMethod.ByAci, 8);
    gs.GridLineStyle = LineStyle.Solid;
    gs.GridLineWeight = LineWeight.LineWeight015;
    gs.GridSpacing = 100;

    double x1 = vp.ViewCenter.X - vp.Width / 2.0;
    double y1 = vp.ViewCenter.Y - vp.Height / 2.0;
    double x2 = vp.ViewCenter.X + vp.Width / 2.0;
    double y2 = vp.ViewCenter.Y + vp.Height / 2.0;

    Point3d startPoint = new Point3d(x1, y1, 0);
    Point3d endPoint = new Point3d(x2, y1, 0);
    gs.CreateGridLine(startPoint, endPoint, vp.NumberOfColumns);



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...