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

Model / Render Type GsClassFactory

4 REPLIES 4
Reply
Message 1 of 5
mbujak
394 Views, 4 Replies

Model / Render Type GsClassFactory

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

4 REPLIES 4
Message 2 of 5
norman.yuan
in reply to: mbujak

Maybe TransientGraphics?

Message 3 of 5
DiningPhilosopher
in reply to: mbujak

Have you looked at the BlockView.NET sample?

Message 4 of 5
mbujak
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

Message 5 of 5
fenton.webb
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
AutoCAD Engineering
Autodesk

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost