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

AutoCAD PLANT 3D - How to get the pipe in the viewport

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
18627796338
510 Views, 3 Replies

AutoCAD PLANT 3D - How to get the pipe in the viewport

img20211105172753.png

I want to change this function to batch function, which can select several pipes.

 

I use the code below to select pipes.

 

Document acDoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionOptions Opts = new PromptSelectionOptions();
Opts.SingleOnly = false;
Opts.RejectPaperspaceViewport = false;
Opts.MessageForAdding = "Select a viewport";
PromptSelectionResult res = ed.GetSelection(Opts);

if (res.Status == PromptStatus.OK)
{
    Autodesk.AutoCAD.EditorInput.SelectionSet ss = res.Value;
    ObjectId[] idarray = ss.GetObjectIds();
    Database db = Application.DocumentManager.MdiActiveDocument.Database;
    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
    using (Transaction myT = tm.StartTransaction())
    {
        foreach (ObjectId entid in idarray)
        {
            Entity entity = (Entity)tm.GetObject(entid, OpenMode.ForWrite, true);
            if (entity.GetType().ToString() == "Autodesk.AutoCAD.DatabaseServices.Viewport")
            {
                Viewport vp = entity as Viewport;
                vp.On = true;
                acDoc.Editor.SwitchToModelSpace();
                PromptSelectionResult res2 = ed.GetSelection();
                if (res2.Status == PromptStatus.OK)
                {
                    SelectionSet ss2 = res.Value;
                    ObjectId[] idarray2 = ss2.GetObjectIds();
                    foreach (ObjectId ent2id in idarray2)
                    {
                        Entity ent2 = (Entity)tm.GetObject(ent2id, OpenMode.ForWrite, true);
                        ed.WriteMessage("\n You Now selected item type: " + ent2.GetType().FullName);
                    }
                }
            }

        }
        //myT.Commit();
    }
}

 

The viewport is in Orthographic DWG, after selected pipes in the viewport, I found the type of the pipes is BlockReference. I need to get the layer and Line Number Tag of the pipe, but I dont know how to get these.

3 REPLIES 3
Message 2 of 4
jabowabo
in reply to: 18627796338
Message 3 of 4
18627796338
in reply to: jabowabo

Thanks, it works. But I still wonder if I can get the line number tag and layer of the pipes inside the Orthographic DWG.
Message 4 of 4
jabowabo
in reply to: 18627796338


@18627796338 wrote:
Thanks, it works. But I still wonder if I can get the line number tag and layer of the pipes inside the Orthographic DWG.

Not possible. The only relevant Plant 3D info the ortho drawing contains for the 2d block is in its Xdata - which is the source drawing PnPID and the source item Handle.

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

Post to forums  

Forma Design Contest


AutoCAD Beta