コード例 #1
0
    ////////////////////////////
    //// Display Rep
    ////
    //// list all the display reps for MassElem and MassGroup for the current display config.
    ////////////////////////////

    private void DisplayReps()
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n====================================================\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Get All the AecDbMassElem/Massgroup Display Reps for the current display config\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================\n");

        Database    db    = Application.DocumentManager.MdiActiveDocument.Database;
        Transaction trans = db.TransactionManager.StartTransaction();

        Autodesk.AutoCAD.EditorInput.Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

        DisplaySet         ds  = new DisplaySet();
        ObjectIdCollection ids = DisplayRepresentationManager.GetActiveDisplayRepresentationSets(db);

        ed.WriteMessage("# of active display sets = " + ids.Count + "\n");

        DisplaySet acds = new DisplaySet();

        try
        {
            //  loop through the active disp sets (i.e., disp sets of active dis confid.)
            foreach (ObjectId id in ids)
            {
                acds = trans.GetObject(id, OpenMode.ForRead) as DisplaySet;
                foreach (ObjectId drid in acds.DisplayRepresentationIds)
                {
                    DisplayRepresentation dr = trans.GetObject(drid, OpenMode.ForRead) as DisplayRepresentation;
                    dr = trans.GetObject(drid, OpenMode.ForRead) as DisplayRepresentation;
                    RXClass rc = dr.WorksWith;
                    if (rc.Name == "AecDbMassElem" || rc.Name == "AecDbMassGroup")
                    {
                        if (ds.DisplayRepresentationIds.Contains(drid))
                        {
                            continue;
                        }
                        else
                        {
                            ds.DisplayRepresentationIds.Add(drid);
                            ListDisplayRep(dr);
                        }
                    }
                }
            }
            trans.Commit();
        }
        catch (System.Exception)
        {
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
        return;
    }
コード例 #2
0
    //  create a display config with a little more information filled.
    private DisplayConfiguration CreateDisplayConfig()
    {
        Database    db    = Application.DocumentManager.MdiActiveDocument.Database;
        Transaction trans = db.TransactionManager.StartTransaction();

        DisplayRepresentationManager drm      = new DisplayRepresentationManager(db);
        ObjectId             currentDisConfId = drm.DisplayConfigurationIdForCurrentViewport;
        DisplayConfiguration currentDisConf   = trans.GetObject(currentDisConfId, OpenMode.ForRead) as DisplayConfiguration;

        DisplayConfiguration dc = new DisplayConfiguration();

        try
        {
            DisplaySet ds = new DisplaySet();
            ds.SetToStandard(db);
            ds.SubSetDatabaseDefaults(db);

            //  top
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 0, 1), DictionaryDisplaySet.GetStandardPlanId(db)));
            //  for bottom. No DictionaryDisplaySet.GetStandardXxxId for Plan Diagnostic, so get it from the name.
            ObjectId id = DictionaryDisplaySet.GetStandardSet("Plan Diagnostic", db);
            if (id != ObjectId.Null)
            {
                dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 0, -1), id));
            }
            else  // if not found, let's use Reflected.
            {
                dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 0, -1), DictionaryDisplaySet.GetStandardReflectedId(db)));  //buttom
            }
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(-1, 0, 0), DictionaryDisplaySet.GetStandardSectionElevId(db))); // left
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(1, 0, 0), DictionaryDisplaySet.GetStandardSectionElevId(db)));  // right
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, -1, 0), DictionaryDisplaySet.GetStandardSectionElevId(db))); //  front
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 1, 0), DictionaryDisplaySet.GetStandardSectionElevId(db)));  // back

            //  try adding DefaultViewDependentViewSet here.
            dc.DefaultViewDependentViewSet = DictionaryDisplaySet.GetStandardModelId(db);

            DictionaryDisplayConfiguration dictDisplayConfigs = new DictionaryDisplayConfiguration(db);
            string newName = GetNewName();
            dictDisplayConfigs.AddNewRecord(newName, dc);
            trans.AddNewlyCreatedDBObject(dc, true);
            trans.Commit();
        }
        catch (System.Exception)
        {
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
        return(dc);
    }
コード例 #3
0
    ////////////////////////////
    //// MATERIALS
    ////////////////////////////

    private void DisplayPropsMaterial()
    {
        Database           db    = Application.DocumentManager.MdiActiveDocument.Database;
        TransactionManager tm    = db.TransactionManager;
        Transaction        trans = db.TransactionManager.StartTransaction();

        try
        {
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("=======================================\n");
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Get all the Display Properties and the Display components works with AecDbMaterialDef in ZAxis view\n");
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("=======================================\n");

            DisplayRepresentationManager drm = new DisplayRepresentationManager(db);
            Viewport         vport           = new Viewport();
            BlockTableRecord btr             = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false);
            btr.AppendEntity(vport);
            trans.AddNewlyCreatedDBObject(vport, true);
            ObjectId viewportId = vport.ObjectId;

            Vector3d   viewDirection = Vector3d.ZAxis;
            ObjectId   setId         = drm.DisplayRepresentationSet(viewportId, viewDirection);
            DisplaySet ds            = trans.GetObject(setId, OpenMode.ForWrite) as DisplaySet;
            DisplayRepresentationIdCollection repIds = ds.DisplayRepresentationIds;
            DisplayRepresentation             dr     = null;
            foreach (ObjectId repId in repIds)
            {
                dr = trans.GetObject(repId, OpenMode.ForRead) as DisplayRepresentation;
                if (dr.WorksWith.Name == "AecDbMaterialDef")
                {
                    ObjectId          dpId = dr.DefaultDisplayPropertiesId;
                    DisplayProperties dp   = trans.GetObject(dpId, OpenMode.ForWrite) as DisplayProperties;
                    ListDisplayProperties(dp);
                }
            }
        }
        catch (System.Exception e)
        {
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message + "\n");
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
        return;
    }
コード例 #4
0
    ////////////////////////////
    //// Display Props
    //// list all the disp reps for the door for the current view port
    ////////////////////////////

    private void DisplayProps()
    {
        Database             db    = Application.DocumentManager.MdiActiveDocument.Database;
        TransactionManager   tm    = db.TransactionManager;
        Transaction          trans = db.TransactionManager.StartTransaction();
        BlockTable           bt    = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
        BlockTableRecord     btr   = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
        DictionaryDisplaySet dds   = new DictionaryDisplaySet(db, false);

        try
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions optEnt = new PromptEntityOptions("Select an AEC door entity");
            optEnt.SetRejectMessage("Selected entity is NOT an AEC door entity, try again...");
            optEnt.AddAllowedClass(typeof(Autodesk.Aec.Arch.DatabaseServices.Door), false);  // Geo is the base class of AEC entities.

            PromptEntityResult resEnt = ed.GetEntity(optEnt);
            if (resEnt.Status != PromptStatus.OK)
            {
                ed.WriteMessage("Selection error - aborting" + "\n");
                return;
            }

            Autodesk.Aec.Arch.DatabaseServices.Door door = trans.GetObject(resEnt.ObjectId, OpenMode.ForRead) as Door;
            ed.WriteMessage("You have selected an " + door.GetRXClass().Name + "\n");

            //  get its style
            Autodesk.Aec.Arch.DatabaseServices.DoorStyle doorstyle = trans.GetObject(door.StyleId, OpenMode.ForRead) as DoorStyle;

            ObjectId doorId = door.ObjectId;
            DisplayRepresentationManager drm = new DisplayRepresentationManager(db);

            ObjectIdCollection    ids = drm.GetDisplayRepresentationIdsFromCurrentViewport(door.GetRXClass());
            DisplayRepresentation dr  = null;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("=======================================\n");
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Get all the Display Representations work with the door for current view port\n");
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("=======================================\n");
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("door disp rep count = " + ids.Count + "\n");

            foreach (ObjectId id in ids)
            {
                dr = trans.GetObject(id, OpenMode.ForRead) as DisplayRepresentation;

                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Display Representation Name: " + dr.Name + " Display Name: " + dr.DisplayName + "\n");

                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Display Representation Name: " + dr.Name + "Display Name" + dr.DisplayName + "\n");
                DisplayProperties dps     = null;
                RXClass           rcProps = dr.DisplayPropertiesClass;
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Display Props Class: " + rcProps.Name + "\n");

                //  find override at instance level.
                ObjectId overId = dr.FindDisplayPropertiesOverride(door);
                if (overId != ObjectId.Null)
                {
                    dps = trans.GetObject(overId, OpenMode.ForRead) as DisplayProperties;
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Element override Display Props Name: " + dps.Name + "Display Name" + dps.DisplayName + "\n");
                    continue;
                }
                ObjectId overstyleId = dr.FindDisplayPropertiesOverride(doorstyle);
                if (overstyleId != ObjectId.Null)
                {
                    dps = trans.GetObject(overstyleId, OpenMode.ForRead) as DisplayProperties;
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Style override Style Display Props Name: " + dps.Name + "Display Name" + dps.DisplayName + "\n");
                    continue;
                }
                ObjectId defaultDpsId = dr.DefaultDisplayPropertiesId;
                if (!defaultDpsId.IsNull)
                {
                    dps = trans.GetObject(defaultDpsId, OpenMode.ForRead) as DisplayProperties;
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Default Display Props Name: " + dps.Name + "Display Name" + dps.DisplayName + "\n");
                }
            }
            trans.Commit();
        }
        catch (System.Exception)
        {
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
        return;
    }
コード例 #5
0
    ////////////////////////////
    //// Display Configuration
    ////////////////////////////

    private void DisplayConfigs()
    {
        //' access the display system from the database object

        Database    db    = Application.DocumentManager.MdiActiveDocument.Database;
        Transaction trans = db.TransactionManager.StartTransaction();

        try
        {
            // Access the display system from the document object
            DictionaryDisplayConfiguration dictDisplayConfigs = new DictionaryDisplayConfiguration(db);

            // The total number of display configurations registered.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + dictDisplayConfigs.Records.Count + " display configs:\n");

            // List them
            foreach (ObjectId dcId in dictDisplayConfigs.Records)
            {
                DisplayConfiguration dc = trans.GetObject(dcId, OpenMode.ForWrite) as DisplayConfiguration;
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Name : " + dc.Name + "\n" +
                                                                                  "Description :  " + dc.Description + "\n");
            }

            // Add a new config with the name "MyConfig" with a description in it.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLet's add a new DisplayConfiguration:\n");
            DisplayConfiguration displayconfig = new DisplayConfiguration();
            displayconfig.Description = "This is MyConfig";
            if (!dictDisplayConfigs.Has("MyConfig", trans))
            {
                dictDisplayConfigs.AddNewRecord("MyConfig", displayconfig);
                trans.AddNewlyCreatedDBObject(displayconfig, true);
            }

            // Add another one "FORUSE1"
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(displayconfig.Name + " : " + displayconfig.Description + "\n");
            DisplayConfiguration displayconfig1 = new DisplayConfiguration();
            displayconfig1.Description = "This is for use";
            if (!dictDisplayConfigs.Has("FORUSE1", trans))
            {
                dictDisplayConfigs.AddNewRecord("FORUSE1", displayconfig1);
                trans.AddNewlyCreatedDBObject(displayconfig1, true);
            }

            //    rename MyConfig to a new name MyNewConfigureXxx
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLet's rename this new DisplayConfiguration:\n");
            string newName = GetNewName();
            dictDisplayConfigs.Rename("MyConfig", newName, trans);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("After Renamed:\nName: " + displayconfig.Name + "\nDescription: " + displayconfig.Description + "\n");


            //    report the total number of display config again.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + dictDisplayConfigs.Records.Count + " display configurations now.\n");

            //    the ObjectId of the new disp config?
            ObjectId nid = dictDisplayConfigs.GetAt(newName);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The current ObjectId for new display configuration is:" + nid.ToString() + "\n");

            //    the current active config?
            DisplayRepresentationManager drm      = new DisplayRepresentationManager(db);
            ObjectId             currentDisConfId = drm.DisplayConfigurationIdForCurrentViewport;
            DisplayConfiguration currentDisConf   = trans.GetObject(currentDisConfId, OpenMode.ForRead) as DisplayConfiguration;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The Current DisplayConfiguration is " + currentDisConf.Name + "\n");
            ListDisplayConfig(currentDisConf);

            //    create a new disp config with more detailed information.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Let's create a new DisplayConfiguration for detail:\n");
            DisplayConfiguration newDc = CreateDisplayConfig();

            //    print it out
            ListDisplayConfig(newDc);

            trans.Commit();
        }
        catch (System.Exception e)
        {
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Exception: " + e.Message + "\n");
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
    }
コード例 #6
0
    /// <summary>
    /// Let user select a wall and override one display properties of this wall.
    /// User can see the different display of this wall.
    /// </summary>
    public void DisplayPropertiesWallSample()
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplay Properties Wall Sample:\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================\n");

        Database db = Application.DocumentManager.MdiActiveDocument.Database;

        //MaterialUtility.
        TransactionManager tm    = db.TransactionManager;
        Transaction        trans = tm.StartTransaction();
        Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;

        try
        {
            PromptEntityOptions optEnt = new PromptEntityOptions("Select an AEC Wall entity");
            optEnt.SetRejectMessage("Selected entity is NOT an AEC Wall entity, try again...");
            optEnt.AddAllowedClass(typeof(Autodesk.Aec.Arch.DatabaseServices.Wall), false);  // Geo is the base class of AEC entities.

            PromptEntityResult resEnt = ed.GetEntity(optEnt);
            if (resEnt.Status != PromptStatus.OK)
            {
                throw new System.Exception("Selection error - aborting");
            }

            Wall pickedWall = trans.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Wall;

            DisplayRepresentationManager displayManager = new DisplayRepresentationManager(db);
            ObjectIdCollection           ids            = displayManager.GetDisplayRepresentationIdsFromCurrentViewport(RXClass.GetClass(typeof(Wall)));

            ObjectId activeDisplayRepId = ids[0];

            DisplayPropertiesWallPlan wallProperties = new DisplayPropertiesWallPlan();

            wallProperties.SubSetDatabaseDefaults(db);
            wallProperties.SetToStandard(db);
            System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();

            DisplayComponent[] components = wallProperties.GetDisplayComponents(out sc);
            int index = -1;
            for (int i = 0; i < sc.Count; i++)
            {
                string componentName = sc[i];
                //Here, we override the display properties for "shrink wrap" and display it on the screen.
                if (componentName == "Shrink Wrap")
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                throw new System.Exception("Lack of display component.");
            }

            DisplayComponentEntity component = components[index] as DisplayComponentEntity;
            component.IsApplicable  = true;
            component.IsVisible     = true;
            component.ByMaterial    = false;
            component.ColorIndex    = 30;
            component.LinetypeScale = 2;
            component.LineWeight    = LineWeight.LineWeight070;

            ObjectId dispWallId = Override.AddToOverrideExtensionDictionaryAndClose(pickedWall, wallProperties);
            OverrideDisplayProperties overrideProperties = new OverrideDisplayProperties();
            overrideProperties.ViewId            = activeDisplayRepId;
            overrideProperties.DisplayPropertyId = dispWallId;
            pickedWall.Overrides.Add(overrideProperties);

            trans.Commit();
        }
        catch (System.Exception e)
        {
            trans.Abort();
            ed.WriteMessage("\n" + e.Message + "\n");
        }
    }
コード例 #7
0
    /// <summary>
    /// Create a material style and override the display properties of this style.
    /// Use Stylemanager to see the overrided display properties.
    /// </summary>
    public void DisplayPropertiesMaterialSample()
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDisplay Properties for Material Sample:\n");
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("====================================================\n");

        Database db = Application.DocumentManager.MdiActiveDocument.Database;

        //MaterialUtility.
        TransactionManager tm    = db.TransactionManager;
        Transaction        trans = tm.StartTransaction();
        Editor             ed    = Application.DocumentManager.MdiActiveDocument.Editor;

        Autodesk.Aec.DatabaseServices.Dictionary dict = new DictionaryMaterialDefinition(db);

        MaterialDefinition materialDefinition = null;

        try
        {
            string name        = "ACADotNetMaterialDefination";
            string description = "Material def created through .NET API";

            if (!dict.Has(name, trans))
            {
                materialDefinition             = dict.NewEntry() as MaterialDefinition;
                materialDefinition.Description = description;
                dict.AddNewRecord(name, materialDefinition);
                trans.AddNewlyCreatedDBObject(materialDefinition, true);
            }
            else
            {
                materialDefinition = trans.GetObject(dict.GetAt(name), OpenMode.ForWrite) as MaterialDefinition;
            }



            DisplayPropertiesMaterial materialProperties = new DisplayPropertiesMaterial();

            materialProperties.SubSetDatabaseDefaults(db);
            materialProperties.SetToStandard(db);

            ObjectId materialId = AddMaterial("wood");
            materialProperties.SurfaceRenderingMaterialId       = materialId;
            materialProperties.SectionRenderingMaterialId       = materialId;
            materialProperties.SectionedBodyRenderingMaterialId = materialId;
            DisplayComponentHatch displayComponentHatch = new DisplayComponentHatch();

            materialProperties.SurfaceHatch.HatchType   = HatchType.UserDefined;
            materialProperties.SurfaceHatch.PatternName = "NETAPITESTPatternName";
            materialProperties.SurfaceHatch.Angle       = 90.0;

            ObjectId dispMaterialId = Override.AddToOverrideExtensionDictionaryAndClose(materialDefinition, materialProperties);

            DisplayRepresentationManager displayManager = new DisplayRepresentationManager(db);
            ObjectIdCollection           ids            = displayManager.GetDisplayRepresentationIdsFromCurrentViewport(RXObject.GetClass(typeof(MaterialDefinition)));

            ObjectId idActiveDispRep = ids[0];

            OverrideDisplayProperties overrideProperties = new OverrideDisplayProperties();
            overrideProperties.ViewId            = idActiveDispRep;
            overrideProperties.DisplayPropertyId = dispMaterialId;
            materialDefinition.Overrides.Add(overrideProperties);

            trans.Commit();
            ed.WriteMessage("\n" +
                            "One new style for material \"ACADotNetMaterialDefination\"is created and the display properties are overrided.\n" +
                            "Use StyleManager to see the settings."
                            + "\n");
        }
        catch (System.Exception e)
        {
            trans.Abort();
            ed.WriteMessage("\n" + e.Message + "\n");
            return;
        }
    }