Results 1 to 3 of 3

Thread: Create MultiViewBlockReference with .NET

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2009-05
    Posts
    1
    Login to Give a bone
    0

    Default Create MultiViewBlockReference with .NET

    Hello,

    Does anyone have a example how to insert a MultiViewBlockReference with .NET in ACA?
    I have a MultiViewBlock created with the Name TestBlock and want to create a Reference in the drawing.

    For so far as i discoverd i have to make a new MultiViewBlockReference object and set the defaults.
    But how do i set the insertionpoint and the the link to the MultiViewBlock definition?


    Regards,

    Marco

  2. #2
    Member
    Join Date
    2014-04
    Posts
    4
    Login to Give a bone
    0

    Default Re: Create MultiViewBlockReference with .NET

    Quote Originally Posted by mgreven View Post
    Hello,

    Does anyone have a example how to insert a MultiViewBlockReference with .NET in ACA?
    I have a MultiViewBlock created with the Name TestBlock and want to create a Reference in the drawing.

    For so far as i discoverd i have to make a new MultiViewBlockReference object and set the defaults.
    But how do i set the insertionpoint and the the link to the MultiViewBlock definition?


    Regards,

    Marco
    Hi mgreven!
    Try this:

    Code:
        public class MvBlockPlacer : DrawJig
        {
            private Point3d previousCurserPosition;
            private Point3d currentCurserPosition;
            private Entity entityToDrag;
            private Database db = Application.DocumentManager.MdiActiveDocument.Database;
            private Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            private int mPromptCounter;
            private string sampstatus;
            private double rotationadj;
            private string jiginput;
            private string jigmsg;
    
            private ObjectId retObjID;
    
    
            public void StartJig(string MvBlockName)
            {
                string blockname = null;
                rotationadj = 0;
                // Double
                mPromptCounter = 0;
                // integer
                blockname = MvBlockName;
    
    
                
                Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition mvbstyledict = default(Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition);
    
    
                ObjectId bstyleID = default(ObjectId);
                Autodesk.Aec.DatabaseServices.MultiViewBlockReference mvb = default(Autodesk.Aec.DatabaseServices.MultiViewBlockReference);
                mvb = new Autodesk.Aec.DatabaseServices.MultiViewBlockReference();
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
         
                mvbstyledict = new Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition(db);
    
    
                bstyleID = mvbstyledict.GetAt(blockname);
    
    
                mvb.BlockDefId = bstyleID;
    
    
                entityToDrag = mvb;
    
    
                previousCurserPosition = new Point3d(0,0,0);
                sampstatus = "NoChange";
                while (sampstatus == "NoChange")
                {
                    Application.DocumentManager.MdiActiveDocument.Editor.Drag(this);
                    //SamplerStatus then World draw runs from here
                    mvb.Rotation = rotationadj;
                }
    
    
                mPromptCounter = 1;
                if (sampstatus == "OK")
                {
                    using (Transaction myT = tm.StartTransaction())
                    {
                        // Dim doc1 As Document = Application.DocumentManager.MdiActiveDocument
                        // Dim dl As DocumentLock = doc1.LockDocument
                        Document doc = Application.DocumentManager.MdiActiveDocument;
                        using (DocumentLock acLckDoc = doc.LockDocument())
                        {
                            BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                            BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                            btr.AppendEntity(mvb);
                            tm.AddNewlyCreatedDBObject(mvb, true);
                            // Возвращаем значение нового ObjectID для блока
                            retObjID = mvb.ObjectId;
                            myT.Commit();
                        }
                    }
                }
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions jigOpts = new JigPromptPointOptions();
                jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.AcceptOtherInputString);
                if (mPromptCounter == 0)
                {
                    jigOpts.Message = "\r\n" + "Pick insertion point ..." + "\r\n";
                    //jigOpts.
                    PromptPointResult dres = prompts.AcquirePoint(jigOpts);
                    currentCurserPosition = dres.Value;
                    if (dres.Status == PromptStatus.Cancel)
                    {
                        sampstatus = "Cancel";
                        return SamplerStatus.Cancel;
                    }
                    if (currentCurserPosition == previousCurserPosition)
                    {
                        //If currentCurserPosition <> previousCurserPosition Then
                        sampstatus = "OK";
                        return SamplerStatus.OK;
                    }
                    if (dres.StringResult != null)
                    {
                        // Here put switch case for keywords.
                        jigmsg = dres.StringResult;
                        switch (jigmsg)
                        {
                            case "NAme":
                                ed.WriteMessage("\r\n" + "NAme");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                            case "Xscale":
                                ed.WriteMessage("\r\n" + "Xscale");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                            case "Yscale":
                                ed.WriteMessage("\r\n" + "Yscale");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                            case "Zscale":
                                ed.WriteMessage("\r\n" + "Zscale");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                            case "Rotation":
                                // Convert rad to degree  rotationadj = (jigdbl * 3.14159265358979) / 180;
                                sampstatus = "NoChange";
                                mPromptCounter = 1;
                                return SamplerStatus.NoChange;
                            case "Match":
                                ed.WriteMessage("\r\n" + "Match");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                            case "Base":
                                ed.WriteMessage("\r\n" + "Base");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                            default:
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                        }
                    }
                    sampstatus = "NoChange";
                    return SamplerStatus.NoChange;
                }
                else if (mPromptCounter == 1)
                {
                    jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.AcceptOtherInputString);
                    jigOpts.Keywords.Clear();
                    jigOpts.Message = "\r\n" + "Rotation: ";
                    PromptPointResult rres = prompts.AcquirePoint(jigOpts);
                    currentCurserPosition = rres.Value;
                    if (rres.StringResult != null)
                    {
                        jiginput = rres.StringResult.ToString();
                        mPromptCounter = 0;
                        sampstatus = "NoChange";
                        return SamplerStatus.NoChange;
                    }
                    if (rres.Status == PromptStatus.Error)
                    {
                        sampstatus = "Error";
                        return SamplerStatus.NoChange;
                    }
                    if (rres.Status == PromptStatus.Cancel)
                    {
                        sampstatus = "Cancel";
                        return SamplerStatus.Cancel;
                    }
                    if (rres.Status == PromptStatus.Keyword)
                    {
                        sampstatus = "Keyword";
                        return SamplerStatus.NoChange;
                    }
                    if (rres.Status == PromptStatus.Modeless)
                    {
                        sampstatus = "Modeless";
                        return SamplerStatus.NoChange;
                    }
                    if (rres.Status == PromptStatus.None)
                    {
                        sampstatus = "None";
                        return SamplerStatus.NoChange;
                    }
                    if (rres.Status == PromptStatus.Other)
                    {
                        sampstatus = "Other";
                        return SamplerStatus.NoChange;
                    }
                    sampstatus = "NoChange";
                    return SamplerStatus.NoChange;
                }
                else
                {
                    sampstatus = "NoChange";
                    return SamplerStatus.NoChange;
                }
            }
            protected override bool WorldDraw(WorldDraw draw)
            {
                if (mPromptCounter == 1)
                {
                    Vector3d displacementVector = previousCurserPosition.GetVectorTo(currentCurserPosition);
                    entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
                    previousCurserPosition = currentCurserPosition;
                    draw.Geometry.Draw(entityToDrag);
                }
                else
                {
                    Vector3d displacementVector = previousCurserPosition.GetVectorTo(currentCurserPosition);
                    entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
                    previousCurserPosition = currentCurserPosition;
                    draw.Geometry.Draw(entityToDrag);
                }
    
    
                return true;
            }
            public ObjectId returnObjID
    
            {
                get
                {
                    return retObjID;
                }
            }
        }

  3. #3
    Member
    Join Date
    2014-04
    Posts
    4
    Login to Give a bone
    0

    Default Re: Create MultiViewBlockReference with .NET

    Take a look to this code from forums.autodesk.com
    Code:
    using System;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.ApplicationServices;
    using System.Reflection;
    
    using System.IO;
    using System.Collections;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.GraphicsInterface;
    //using Autodesk.Aec.DatabaseServices;
    
    
    namespace mvblockJig
    {
        public class JigExample : DrawJig
        {
            private Point3d previousCurserPosition;
            private Point3d currentCurserPosition;
            private Entity entityToDrag;
            //private Autodesk.Aec.DatabaseServices.Entity entityToDrag;
            private Database db = Application.DocumentManager.MdiActiveDocument.Database;
            private Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            int mPromptCounter;
            string sampstatus;
            double rotationadj;
            string jiginput;
            string jigmsg;
    
            [CommandMethod("placeMvBlock")]
            public void StartJig()
            {
                // test block 113D_362336_MV
                string blockname;
    
                rotationadj = 0;
                mPromptCounter = 0;
                blockname = ed.GetString("Input Block Name").StringResult;
                Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition mvbstyledict;
                ObjectId bstyleID;
                Autodesk.Aec.DatabaseServices.MultiViewBlockReference mvb;
                mvb = new Autodesk.Aec.DatabaseServices.MultiViewBlockReference();
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
                mvbstyledict = new Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition(db);
                bstyleID = mvbstyledict.GetAt(blockname);
    
                mvb.BlockDefId = bstyleID;
    
                entityToDrag = mvb;
                previousCurserPosition = new Point3d(0, 0, 0);
    
                sampstatus = "NoChange";
    
                while (sampstatus == "NoChange")
                {
    
                    Application.DocumentManager.MdiActiveDocument.Editor.Drag(this); //SamplerStatus then World draw runs from here
    
                    mvb.Rotation = rotationadj;
    
    
                }
    
                mPromptCounter = 1;
    
    
    
                if (sampstatus == "OK")
                {
    
    
    
                    using (Transaction myT = tm.StartTransaction())
                    {
    
                        BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                        BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                        btr.AppendEntity(mvb);
                        tm.AddNewlyCreatedDBObject(mvb, true);
                        myT.Commit();
                    }
                }
    
            }
    
    
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
    
                JigPromptPointOptions jigOpts = new JigPromptPointOptions();
    
    
                jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.AcceptOtherInputString);
    
    
                if (mPromptCounter == 0)
                {
    
                    jigOpts.Message = "\nInsert point or ";
    
                    jigOpts.Keywords.Add("NAme", "NAme", "NAme", true, true);
                    jigOpts.Keywords.Add("Xscale", "Xscale", "Xscale", true, true);
                    jigOpts.Keywords.Add("Yscale", "Yscale", "Yscale", true, true);
                    jigOpts.Keywords.Add("Zscale", "Zscale", "Zscale", true, true);
                    jigOpts.Keywords.Add("Rotation", "Rotation", "Rotation", true, true);
                    jigOpts.Keywords.Add("Match", "Match", "Match", true, true);
                    jigOpts.Keywords.Add("Base", "Base", "Base", true, true);
    
    
    
                    PromptPointResult dres = prompts.AcquirePoint(jigOpts);
                    currentCurserPosition = dres.Value;
    
    
    
                    if (dres.Status == PromptStatus.Cancel)
                    {
                        sampstatus = "Cancel";
                        return SamplerStatus.Cancel;
    
                    }
    
                    if (currentCurserPosition != previousCurserPosition)
                    {
                        sampstatus = "OK";
                        return SamplerStatus.OK;
                    }
    
                    if (dres.StringResult != null)
                    {
                        // Here put switch case for keywords.
                        jigmsg = dres.StringResult;
    
                        switch (jigmsg)
                        {
                            case "NAme":
                                ed.WriteMessage("\nNAme");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
    
                            case "Xscale":
                                ed.WriteMessage("\nXscale");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
    
                            case "Yscale":
                                ed.WriteMessage("\nYscale");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
    
    
                            case "Zscale":
                                ed.WriteMessage("\nZscale");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
    
    
                            case "Rotation":
    
                                // Convert rad to degree  rotationadj = (jigdbl * 3.14159265358979) / 180;
    
                                sampstatus = "NoChange";
                                mPromptCounter = 1;
    
                                return SamplerStatus.NoChange;
    
                            case "Match":
                                ed.WriteMessage("\nMatch");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
    
                            case "Base":
                                ed.WriteMessage("\nBase");
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
    
                            default:
                                sampstatus = "NoChange";
                                return SamplerStatus.NoChange;
                        }
                    }
    
                    sampstatus = "NoChange";
                    return SamplerStatus.NoChange;
                }
    
                else if (mPromptCounter == 1)
                {
    
                    jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.AcceptOtherInputString);
                    jigOpts.Keywords.Clear();
                    jigOpts.Message = "\nRotation: ";
    
                    PromptPointResult rres = prompts.AcquirePoint(jigOpts);
                    currentCurserPosition = rres.Value;
    
    
                    if (rres.StringResult != null)
                    {
                        jiginput = rres.StringResult.ToString();
                        mPromptCounter = 0;
    
                        sampstatus = "NoChange";
                        return SamplerStatus.NoChange;
    
                    }
    
                    if (rres.Status == PromptStatus.Error)
                    {
                        sampstatus = "Error";
                        return SamplerStatus.NoChange;
                    }
    
    
    
                    if (rres.Status == PromptStatus.Cancel)
                    {
                        sampstatus = "Cancel";
                        return SamplerStatus.Cancel;
    
                    }
    
    
                    if (rres.Status == PromptStatus.Keyword)
                    {
                        sampstatus = "Keyword";
                        return SamplerStatus.NoChange;
                    }
    
    
                    if (rres.Status == PromptStatus.Modeless)
                    {
                        sampstatus = "Modeless";
                        return SamplerStatus.NoChange;
                    }
    
    
                    if (rres.Status == PromptStatus.None)
                    {
                        sampstatus = "None";
                        return SamplerStatus.NoChange;
                    }
    
    
                    if (rres.Status == PromptStatus.Other)
                    {
                        sampstatus = "Other";
                        return SamplerStatus.NoChange;
                    }
    
                    sampstatus = "NoChange";
                    return SamplerStatus.NoChange;
    
    
                }
    
    
                else
                {
                    sampstatus = "NoChange";
                    return SamplerStatus.NoChange;
                }
    
            }
    
    
    
            protected override bool WorldDraw(WorldDraw draw)
            {
                if (mPromptCounter == 1)
                {
                    Vector3d displacementVector = previousCurserPosition.GetVectorTo(currentCurserPosition);
                    entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
                    previousCurserPosition = currentCurserPosition;
                    draw.Geometry.Draw(entityToDrag);
                }
                else
                {
                    Vector3d displacementVector = previousCurserPosition.GetVectorTo(currentCurserPosition);
                    entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
                    previousCurserPosition = currentCurserPosition;
                    draw.Geometry.Draw(entityToDrag);
                }
    
                return true;
            }
        }
    }
    It really works.

Similar Threads

  1. How to jig scaled Multiviewblockreference
    By AntonAlalaev in forum Dot Net API
    Replies: 1
    Last Post: 2014-04-30, 02:49 PM
  2. Replies: 1
    Last Post: 2011-10-02, 05:32 PM
  3. Replies: 11
    Last Post: 2007-09-12, 01:00 PM
  4. Can't create a DWF...
    By sinc in forum AutoCAD Plotting
    Replies: 3
    Last Post: 2007-03-30, 04:45 PM
  5. How to create this in ADT
    By ravikumar_b4u in forum ACA General
    Replies: 5
    Last Post: 2006-06-26, 03:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •