.NET

Reply
Valued Contributor
mbujak
Posts: 53
Registered: ‎07-07-2004
Message 1 of 5 (174 Views)

Model / Render Type GsClassFactory

174 Views, 4 Replies
01-18-2013 11:19 AM

Anyone know the equivalent of getting a AcGsModel with a render type of kDirect similar to that of the old BlockView example in ObjectArx. The function used the AcGsClassFactory::createModel(...) but I cannot seem to find an equivalent to this in .Net.

 

I am currently using an in-memory Database to display graphical objects. Now I want to add "Ghost" objects to the View where they are not added to the Database and displayed over-top of the database resident objects. How can I accomplish this in .Net.

 

Any tips would be appreciated.

 

Thanks

 

Mike

*Expert Elite*
norman.yuan
Posts: 1,017
Registered: ‎04-27-2009
Message 2 of 5 (162 Views)

Re: Model / Render Type GsClassFactory

01-18-2013 03:21 PM in reply to: mbujak

Maybe TransientGraphics?

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 5 (146 Views)

Re: Model / Render Type GsClassFactory

01-20-2013 01:21 AM in reply to: mbujak

Have you looked at the BlockView.NET sample?

Valued Contributor
mbujak
Posts: 53
Registered: ‎07-07-2004
Message 4 of 5 (138 Views)

Re: Model / Render Type GsClassFactory

01-20-2013 06:23 AM in reply to: DiningPhilosopher

I have, and based my view on that. The difference is that the BlockView .Net example does not include the orbit object which the original block view has.

 

- Mike

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 5 of 5 (95 Views)

Re: Model / Render Type GsClassFactory

01-25-2013 11:17 AM in reply to: mbujak

It seems like the transient api is definitely the way for you... Check out Keans blog http://through-the-interface.typepad.com/through_the_interface/2011/03/using-transient-graphics-to-s...

 

In terms of creating an AutoCAD model using .NET, here's some code that might be useful to someone. I wrote it pretty quickly so please excuse any bugs, logic errors.

 

    // command to generate DWG and Block thumbnail bitmaps

    // by Fenton Webb, DevTech, 24/1/2013

    [CommandMethod("GENERATETHUMBS")]

    public void GenerateThumbnailBitmaps()

    {

      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

      // get the output path for the bitmaps

      PromptStringOptions opts = new PromptStringOptions("\nEnter output path : ");

      opts.AllowSpaces = true;

      PromptResult res = ed.GetString(opts);

      // if ok

      if (res.Status == PromptStatus.OK)

      {

        try

        {

          // make sure the folder exists

          DirectoryInfo outputPathInfo = new DirectoryInfo(res.StringResult);

          if (outputPathInfo.Exists)

          {

            Point2d screenSize = (Point2d)Application.GetSystemVariable("SCREENSIZE");

            // set up the image sizes

            int width = (int)screenSize.X;

            int height = (int)screenSize.Y;

 

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            

            // get the dwg file name

            FileInfo dwgPath = new FileInfo(doc.Name);

 

            // get the document graphics system manager

            Manager gsm = doc.GraphicsManager;

 

            // construct the default filename prefix and path

            string defaultPath = outputPathInfo.FullName + "\\" + dwgPath.Name.Replace(".dwg", " ");

 

            // first generate the MS screen shot

            View acadView = gsm.GetGsView(2, true);

            Rectangle rect = new Rectangle(0, 0, width, height);

            using (Bitmap msBmp = acadView.GetSnapshot(rect))

              msBmp.Save(defaultPath + " MS.bmp");

 

            // now set the block sizes to something standard

            width = 800;

            height = 600;

 

            // now generate the layout images

            // first remember the current layout

            string currentLayout = LayoutManager.Current.CurrentLayout;

            // now lets loop the layouts, open the layout dict

            using (DBDictionary layoutDict = db.LayoutDictionaryId.Open(OpenMode.ForRead) as DBDictionary)

            {

              // now iterate the layouts and get the names

              foreach (DBDictionaryEntry layoutEntry in layoutDict)

              {

                string layoutName = layoutEntry.Key;

                LayoutManager.Current.CurrentLayout = layoutName;

 

                using (Bitmap layoutBmp = doc.CapturePreviewImage((uint)width, (uint)height))

                  layoutBmp.Save(defaultPath + " " + layoutName + ".bmp");

                /*View layoutView = gsm.GetGsView(1, true);

                rect = new Rectangle(0, 0, width, height);

                using (Bitmap layoutBmp = layoutView.GetSnapshot(rect))

                  layoutBmp.Save(defaultPath + " " + layoutName + ".bmp");*/

              }

            }

            // restore the original layout 

            LayoutManager.Current.CurrentLayout = currentLayout;

 

            // now create an off screen device

            using (Device offDevice = gsm.CreateAutoCADOffScreenDevice())

            {

              // now size the device

              offDevice.OnSize(new System.Drawing.Size(width, height));

              // now create the view

              using (View view = new View())

              {

                // add the new view object to the device

                offDevice.Add(view);

                // update it

                offDevice.Update();

 

                // ok now create the model

                using (Model model = gsm.CreateAutoCADModel())

                {

                  using (BlockTable bt = db.BlockTableId.Open(OpenMode.ForRead) as BlockTable)

                  {

                    // now iterate through our block tables

                    foreach (ObjectId id in bt)

                    {

                      // open the btr for read

                      using (BlockTableRecord btr = id.Open(OpenMode.ForRead) as BlockTableRecord)

                      {

                        // get the name of the block for the BMP file name

                        string btrName = btr.Name;

 

                        // add the btr to the view

                        view.Add(btr, model);

 

                        try

                        {

                          // get the extents of the btr

                          Extents3d extents = new Extents3d();

                          extents.AddBlockExtents(btr);

                          // now zoom extents of the view

                          view.ZoomExtents(extents.MinPoint, extents.MaxPoint);

 

                          // finally, construct the filepath

                          string imagePath = defaultPath + btrName + " Block.bmp";

                          // clean up the path

                          imagePath = imagePath.Replace("*", "");

                          // snap the image

                          rect = new Rectangle(0, 0, width, height);

                          using (Bitmap blockBmp = view.GetSnapshot(rect))

                            blockBmp.Save(imagePath);

                        }

                        catch

                        {

                        }

 

                        // reset the view for the next iteration

                        view.EraseAll();

                      }

                    }

                  }                  

                }

                offDevice.EraseAll();

              }

            }

          }

          else

            ed.WriteMessage("\nThe Path is invalid: " + res.StringResult);

        }

        catch

        {

          ed.WriteMessage("\nThe Path cannot be written to: " + res.StringResult);

        }

      }

    }





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.