Author Topic: Layout creation tool  (Read 16516 times)

0 Members and 1 Guest are viewing this topic.

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #30 on: August 28, 2008, 04:53:39 AM »
For my next trick, I've been trying to get to grips with groups.

As part of the process of creating the new layouts, my method for creating what we call a "Keyplan" involved, (In VBA at least) creating a group and then zooming to that group. (The same way I would do it if I were doing so manually.)

I've been wondering this morning whether I need to bother doing that any more. given the following code (originally from Kean): -

// (the usual "usings" are required in order to make this work: -

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
// This is a special one:
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[CommandMethod ("ZE")]
public static void ZoomToEntity(ObjectId GroupId)
{
  Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  Database db = doc.Database;
  Editor ed = doc.Editor;
 
  //Extract the extents of the "group"
 
  Extents3d ext;
  Transaction tr = db.TransactionManager.StartTransaction();
  using (tr)
  {
    Entity ent = (Entity)tr.GetObject(GroupId, OpenMode.ForRead);
    ext = ent.GeometricExtents;
    tr.Commit();
  }

  ext.TransformBy(ed.CurrentUserCoordinateSystem.Inverse());
 
  // Call our helper function
 
  private static void ZoomWin(Editor ed, Point3d min, Point3d max)
  {

      Point2d min2d = new Point2d(min.X, min.Y);
      Point2d max2d = new Point2d(max.X, max.Y);
      ViewTableRecord view =  new ViewTableRecord();
      view.CenterPoint =  min2d + ((max2d - min2d) / 2.0);
      view.Height = max2d.Y - min2d.Y;
      view.Width = max2d.X - min2d.X;
      ed.SetCurrentView(view);
  }

I guess I would just need to create an object (in my case a user-defined rectangle) and then store the ObjectId of said Object for when it's time to create the viewports.  :|

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #31 on: September 01, 2008, 05:05:54 AM »
Right, I seem to have fudged the look/layout of my creation tool: -

I'm pretty sure I haven't broken anything in AutoCAD but whereas when I started writing this tool I'd get the options appearing next to the cursor, (when I prompt the user for input using either a PromptPointOptions, PrompStringOptions, or Prompt now, all I get is the command-line prompt. Can anyone offer an explanation as to how to fix this?

(Code attached for testing purposes)

Glenn R

  • Guest
Re: Layout creation tool
« Reply #32 on: September 01, 2008, 02:12:20 PM »
You've probably switched Dynamic Input off - it's the 'DYN' button (from memory) on the application status bar at the bottom of AutoCAD's main window.

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #33 on: September 01, 2008, 03:48:58 PM »
You've probably switched Dynamic Input off - it's the 'DYN' button (from memory) on the application status bar at the bottom of AutoCAD's main window.
That's strange - I don't remember turning that feature off. I shall take a look tomorrow morning. Cheers Glenn. :)

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #34 on: September 02, 2008, 04:22:50 AM »
You've probably switched Dynamic Input off - it's the 'DYN' button (from memory) on the application status bar at the bottom of AutoCAD's main window.
That was the problem mate, cheers. :) A typical case of RTFM :-o

Glenn R

  • Guest
Re: Layout creation tool
« Reply #35 on: September 02, 2008, 04:54:01 AM »
:D

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #36 on: September 03, 2008, 05:09:55 PM »
Right, I seem to have reached a bit of an impasse.

In my VBA implementation of this solution, the next stage of the process involved populating an array with several pieces of information in order to then create the new viewports that will be required: -

(Below are just some of the information that needs to be captured.)

Block location (Double Values) (which would I guess translate to Position3d values in C#)
specific Attribute location (In order to locate the centre of a new viewport) (Double Values) (again these would now be Position3d values)
Scale values (String Value)
Ucs to align to (String value)

(It's just dawned on me that rather than re-traversing the modelspace blocktable I should collate this information when the blocks are being inserted. After all, I'm already editing attributes that I would otherwise revisit at this stage.)

I'm a bit puzzled as to how I should proceed from here. Can anyone point in the right direction?

Glenn R

  • Guest
Re: Layout creation tool
« Reply #37 on: September 03, 2008, 05:13:45 PM »
Claaaaassss.

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #38 on: September 03, 2008, 05:15:22 PM »

Glenn R

  • Guest
Re: Layout creation tool
« Reply #39 on: September 03, 2008, 05:26:52 PM »
Without seeing more of the current and previous VBA implentation, as well as not having a good mental picture of what you're trying to accomplish (ie not being close to the idea/development), I would create a class object with all the properties you need, toss this into a List<YourClassNameHere> and use that..............or you might use a generic Dictionary.........

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #40 on: September 08, 2008, 07:35:03 AM »
Without seeing more of the current and previous VBA implentation, as well as not having a good mental picture of what you're trying to accomplish (ie not being close to the idea/development), I would create a class object with all the properties you need, toss this into a List<YourClassNameHere> and use that..............or you might use a generic Dictionary.........
Right, having spent a couple of days doing other things, (Mowing the lawn amongst them) I think I've almost got a working Viewport class sorted out. (at least, it contains the properties I want to store for use later on) I am however having trouble figuring out what you meant by "List<YourClassNameHere>"??

Maybe I'm googling the wrong thing...?

EDIT:
Code: [Select]
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<String> names = new List<String>();
        names.Add("Bruce");
        names.Add("Alfred");
        names.Add("Tim");
        names.Add("Richard");

        // Display the contents of the List out using the "Print" delegate.
        names.ForEach(Print);

        // The following demonstrates the Anonymous Delegate feature of C#
        // to display the contents of the List to the console.
        names.ForEach(delegate(String name)
        {
            Console.WriteLine(name);
        });
    }

    private static void Print(string s)
    {
        Console.WriteLine(s);
    }
}
/* This code will produce output similar to the following:
 * Bruce
 * Alfred
 * Tim
 * Richard
 * Bruce
 * Alfred
 * Tim
 * Richard
 */

Is the above (from here) similar to what you meant?


Glenn R

  • Guest
Re: Layout creation tool
« Reply #41 on: September 08, 2008, 07:40:09 AM »
WRT the List container bit - yes. That's essentially what I meant.

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #42 on: September 10, 2008, 10:39:46 AM »
Right, I've managed to store in a list the properties I need to create the viewports/layouts using Glenn's post here as a reference.

Here's my Vports class: -

Code: [Select]
public class Vports
{
 public string vpName { get; set; }
 public string vpScale { get; set; }
 public Point3d vpPSCentrePoint { get; set; }
 public Point3d vpMSCentrePoint { get; set; }
 public string FullorPartial { get; set; }
 public vpVisProp { get; set; }
 public vpHeight {get; set; }
 public vpWidth {get; set; }
 public PageSize { get; set; }
}

My next step is to pass this information to my LayoutCommands class and use it to create the new required layouts.

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #43 on: January 04, 2010, 06:16:29 AM »
I realise it's been some time since I updated this thread, but I recently found some time to continue my work on this tool:

If the user has already inserted some blocks, but doesn't add any new ones (if say for instance the user is updating the drawing with a view they missed) I've been struggling with how to collect the necessary information from the existing blocks. I hoped to be able to simply add the ObjectId for each existing block to a custom dictionary for later retrieval but am yet to understand how to do this without parsing through the block table at this level.

Thinking about it now, I think parsing the block table at this stage would be easier/simpler than passing dictionaries/lists up/down through my procedure?

(I hope that all makes sense :-o )

PS. I've also found a neat way of visualising the stages in my procedure (see attached)

vegbruiser

  • Guest
Re: Layout creation tool
« Reply #44 on: November 16, 2010, 09:33:43 AM »
Hi folks,

It's me and my zombie thread again.  :lol:

I've managed to pick this up yet again in an attempt to finally finish it off - I can't believe I never did after all this time!

Anywho, I've hit upon an interesting (and annoying!) problem I hope you can help me with.

The attached code runs all the way through without error on 2 different machines - assuming you copy Viewport-blocks.dwg to C:\

The first machine is running AutoCAD 2009 and the code will run all the way through without throwing an error. The block(s) are inserted, and the attributes are filled out correctly- everybody’s happy.

The second machine is running AutoCAD 2011 and the code will also run through without an error. However, when it gets to the following section, blkrefIds.Count is always zero.

Code: [Select]
btr = tr.GetObject(btrid, OpenMode.ForRead, false) as BlockTableRecord;
if (btr.IsLayout || btr.IsFromExternalReference || !btr.IsDynamicBlock || btr.IsFromOverlayReference || !btr.HasAttributeDefinitions)
{
continue;
}
ObjectIdCollection blkrefIds = GetBlockReferenceIds(btr.ObjectId);
if (blkrefIds == null || blkrefIds.Count == 0)
break;

I originally copied portions of this code from TTIF back in 2008, can you shed any immediate thoughts on my problem before I turn to the Autodesk Forums for assistance?

In case it was just me, I tried this code on a third machine running AutoCAD 2010 and the result is the same as with 2011 - the initial blocks are inserted, but blkrefIds.Count is always zero. What am I missing?

Thanks again,

Alex.