Author Topic: Using VB.Net to Import/Insert a DXF File in Existing Drawing  (Read 28677 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #15 on: March 12, 2011, 08:12:36 PM »
yes, I woke up at 0250 thinking about just that.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #16 on: March 13, 2011, 06:05:49 AM »
Hate that.

kaefer

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #17 on: March 13, 2011, 06:55:01 AM »
Has anybody tried:

1. New 'side database'
2. DxfIn method on new 'side database' to insert dxf file into new pristine database
3. insert the new 'side database' with dxf info into current drawing

Hey, that's not fair. It's the .NET way, it has kind of diagnostics; worst of all I don't need my dyn op implementation anymore.

Anyway, here's the workaround for the Import method outlined before, as complete F#.
Code: [Select]
open Autodesk.AutoCAD.DatabaseServices
open Autodesk.AutoCAD.EditorInput
open Autodesk.AutoCAD.Geometry
open Autodesk.AutoCAD.Runtime
type acApp = Autodesk.AutoCAD.ApplicationServices.Application

open System.Reflection
open Microsoft.FSharp.Reflection

let (?) (o: obj) name : 'R =
    if FSharpType.IsFunction(typeof<'R>) then
        let (argType, resType) = FSharpType.GetFunctionElements(typeof<'R>)
        let toArray args =
            if argType = typeof<unit> then [| |]
            elif not(FSharpType.IsTuple argType) then [| args |]
            else FSharpValue.GetTupleFields args
        let checkUnit = if resType = typeof<unit> then fun _ -> box() else id
        FSharpValue.MakeFunction(typeof<'R>, fun args ->
            o.GetType().InvokeMember(
                name, BindingFlags.InvokeMethod ||| BindingFlags.GetProperty, null, o, toArray args)
            |> checkUnit )
    else
        o.GetType().InvokeMember(name, BindingFlags.InvokeMethod ||| BindingFlags.GetProperty, null, o, null)
    |> unbox<'R>

[<CommandMethod "MYDXFIN">]
let myDxfIn() =
    let doc = acApp.DocumentManager.MdiActiveDocument
    let db = doc.Database
    let ed = doc.Editor
    let dialog =   
        new System.Windows.Forms.OpenFileDialog(
            CheckFileExists = true,
            CheckPathExists = true,
            DefaultExt = "dxf",
            DereferenceLinks = true,
            Filter = "DXF Files (*.dxf)|*.dxf|All files (*.*)|*.*" ,
            Title = "Select dxf file" )
    if dialog.ShowDialog()  = System.Windows.Forms.DialogResult.OK then
        let ppr = ed.GetPoint "Insertion point"
        if ppr.Status = PromptStatus.OK then
            let par =
                new PromptAngleOptions(
                    "Rotation",
                    BasePoint = ppr.Value,
                    UseAngleBase = true )
                |> ed.GetAngle
            if par.Status = PromptStatus.OK then
                let pdr = ed.GetDouble "Scale factor"
                if pdr.Status = PromptStatus.OK then
                    let objs = new ResizeArray<_>()
                    (
                        use objectAppended =
                            db.ObjectAppended
                            |> Observable.subscribe
                                (fun e -> objs.Add e.DBObject.ObjectId)
                        doc.AcadDocument?Import(dialog.FileName, Point3d.Origin.ToArray(), 1.)
                    )
                    let mat =
                        Matrix3d.Scaling(pdr.Value, Point3d.Origin) *
                        Matrix3d.Rotation(par.Value, Vector3d.ZAxis, Point3d.Origin) *
                        Matrix3d.Displacement(ppr.Value - Point3d.Origin)
                    use tr = db.TransactionManager.StartTransaction()
                    for oid in objs do
                        (tr.GetObject(oid, OpenMode.ForWrite) :?> Entity).TransformBy mat
                    tr.Commit()
                    objs |> Array.ofSeq |> ed.SetImpliedSelection

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #18 on: March 13, 2011, 09:22:58 AM »


This is what I've been playing with.
It seems fairly stable
The code could be optimised a little, but I left it as was 'cause it was easier to test that way :)
Code: [Select]

// CodeHimBelonga kdub@theSwamp 20100922
// Updated 20110312
// Updated 20110313 workaround for Import bug
//
using System;
using System.IO;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
//
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcUtils = Autodesk.AutoCAD.Internal.Utils;

[assembly: CommandClass(typeof(Ducks.MyCommands))]

namespace Ducks
{
    public class MyCommands
    {
        [CommandMethod("ImportDXF", (CommandFlags.Modal & CommandFlags.Session))]
        public void DucksIn_4()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            //------------------------------------------------------------------
            OpenFileDialog dialog = new OpenFileDialog {
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt = "dxf",
                DereferenceLinks = true,
                Filter = "DXF Files (*.dxf)|*.dxf|All files (*.*)|*.*",
                Title = "Select dxf file"
            };
            if(dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            //------------------------------------------------------------------
            PromptPointResult ppr = ed.GetPoint("Insertion point");
            if(ppr.Status != PromptStatus.OK)
                return;
            //------------------------------------------------------------------
            PromptDoubleOptions pdo = new PromptDoubleOptions("Scale factor");
            pdo.AllowZero = false;
            pdo.AllowNone = false;
            pdo.DefaultValue = 1;
            PromptDoubleResult pdr = ed.GetDouble(pdo);
            if(pdr.Status != PromptStatus.OK)
                return;
            //------------------------------------------------------------------
            string fn = dialog.FileName;
            Point3d toPoint = ppr.Value;           
            double insScale = pdr.Value;

            ObjectId lastEnt = AcUtils.EntLast();

            double[] baseArray = Point3d.Origin.ToArray();
            AcadDocument comDoc = (Autodesk.AutoCAD.Interop.AcadDocument) doc.AcadDocument;
            comDoc.Import(fn, (object)baseArray, insScale);
            //------------------------------------------------------------------

            ObjectIdCollection idColl = new ObjectIdCollection();

            using (Transaction tr = doc.TransactionManager.StartTransaction())
                {
                // if the db is empty lastent will be null               
                    if(lastEnt == ObjectId.Null) {
                        lastEnt = AcUtils.EntFirst();
                        idColl.Add(lastEnt);
                    }
                    ObjectId nextent = AcUtils.EntNext(lastEnt);
                    while(nextent != ObjectId.Null)
                    {
                        idColl.Add(nextent);
                        nextent = AcUtils.EntNext(nextent);
                    }
                    Vector3d vector = (Vector3d)(toPoint - Point3d.Origin);
                    Matrix3d transform = Matrix3d.Displacement(vector);
                    foreach(ObjectId id in idColl)
                    {
                        ((Entity)tr.GetObject(id, OpenMode.ForWrite, true)).TransformBy(transform);
                    }
                    tr.Commit();
                }
        }
    }
}

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #19 on: March 13, 2011, 09:38:53 AM »
Rather amusing.
I just finished posting the code and looked at it in the forum code pane

... realised it will go spacoid if the UCS is other than world ... so need to run a UCS2WCS translation on the Selected Point.

Something to play with tomorrow :)


added :
kaefer,
Just tried to read your code ... realised I shall need to spend some time learning to read F# :)
« Last Edit: March 13, 2011, 09:43:07 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kaefer

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #20 on: March 13, 2011, 11:48:24 AM »
Rather amusing.
I just finished posting the code and looked at it in the forum code pane

... realised it will go spacoid if the UCS is other than world ... so need to run a UCS2WCS translation on the Selected Point.

The benign case is always to simply ignore the UCS settings. Let the user figure out the damn transformation.

Quote
... realised I shall need to spend some time learning to read F#

Shan't. My humble C# version (equally UCS unaware) is here. BTW, what do y'all think about object initializers?
Code: [Select]
    public class MyDxfInCmdClass
    {
        IList<ObjectId> objs;

        [CommandMethod("MyDxfIn")]
        public void MyDxfInCmd()
        {
            objs = new List<ObjectId>();
            Document doc = AcApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            var dialog = new System.Windows.Forms.OpenFileDialog
            {
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt = "dxf",
                DereferenceLinks = true,
                Filter = "DXF Files (*.dxf)|*.dxf|All files (*.*)|*.*" ,
                Title = "Select dxf file"
            };
            if(dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            var ppr = ed.GetPoint("Insertion point");
            if(ppr.Status != PromptStatus.OK)
                return;
            var pda = new PromptAngleOptions("Rotation")
            {
                BasePoint = ppr.Value,
                DefaultValue = 0.0,
                UseAngleBase = true
            };
            var par = ed.GetAngle(pda);
            if(par.Status != PromptStatus.OK)
                return;
            var pdo = new PromptDoubleOptions("Scale factor")
            {
                AllowZero = false,
                AllowNone = false,
                DefaultValue = 1.0
            };
            var pdr = ed.GetDouble(pdo);
            if(pdr.Status != PromptStatus.OK)
                return;
            db.ObjectAppended += new ObjectEventHandler(ObjectAppended);
            try
            {
                Invoke(doc.AcadDocument, "Import", dialog.FileName, ppr.Value.ToArray(), pdr.Value);
            }
            finally
            {
                db.ObjectAppended -= new ObjectEventHandler(ObjectAppended);
            }
            var mat = Matrix3d.Scaling(pdr.Value, Point3d.Origin) *
                Matrix3d.Rotation(par.Value, Vector3d.ZAxis, Point3d.Origin) *
                Matrix3d.Displacement(ppr.Value - Point3d.Origin);
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId oid in objs)
                    ((Entity)tr.GetObject(oid, OpenMode.ForWrite)).TransformBy(mat);
                tr.Commit();
            }
            ObjectId[] ids = new ObjectId[objs.Count];
            objs.CopyTo(ids, 0);
            ed.SetImpliedSelection(ids);
        }
        void ObjectAppended(object sender, ObjectEventArgs e)
        {
            objs.Add(e.DBObject.ObjectId);
        }
        static object Invoke(object o, string name, params object[] args)
        {
            return o.GetType().InvokeMember(name, System.Reflection.BindingFlags.InvokeMethod, null, o, args);
        }
    }

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #21 on: March 14, 2011, 04:08:50 AM »
Something to play with :

Accounts Co-ordinate System other than WCS for insertion Point.

Code: [Select]

// CodeHimBelonga kdub@theSwamp 20100922
// Updated 20110312
// Updated 20110313 workaround for Import bug
// Updated 20110314 translate UCS to WCS for move.
//
using System;
using System.IO;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
//
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcUtils = Autodesk.AutoCAD.Internal.Utils;

[assembly: CommandClass(typeof(Ducks.MyCommands))]

namespace Ducks
{
    public class MyCommands
    {
        [CommandMethod("ImportDXF", CommandFlags.Session)]
        public void DucksIn_5()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            //------------------------------------------------------------------
            OpenFileDialog dialog = new OpenFileDialog {
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt = "dxf",
                DereferenceLinks = true,
                Filter = "DXF Files (*.dxf)|*.dxf|All files (*.*)|*.*",
                Title = "Select dxf file"
            };
            if(dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            //------------------------------------------------------------------
            PromptPointResult ppr = ed.GetPoint("Insertion point");
            if(ppr.Status != PromptStatus.OK)
                return;
            //------------------------------------------------------------------
            PromptDoubleOptions pdo = new PromptDoubleOptions("Scale factor");
            pdo.AllowZero = false;
            pdo.AllowNone = false;
            pdo.DefaultValue = 1;
            PromptDoubleResult pdr = ed.GetDouble(pdo);
            if(pdr.Status != PromptStatus.OK)
                return;
            //------------------------------------------------------------------
            string fn = dialog.FileName;
            double insScale = pdr.Value;

            ObjectId lastEnt = AcUtils.EntLast();

            double[] baseArray = Point3d.Origin.ToArray();

            AcadDocument comDoc = (Autodesk.AutoCAD.Interop.AcadDocument)doc.AcadDocument;
            comDoc.Import(fn, (object)baseArray, insScale);
            //------------------------------------------------------------------
            ObjectIdCollection idColl = new ObjectIdCollection();

            using(Transaction tr = doc.TransactionManager.StartTransaction()) {
                // if the db is empty lastent will be null                
                if(lastEnt == ObjectId.Null) {
                    lastEnt = AcUtils.EntFirst();
                    idColl.Add(lastEnt);
                }
                ObjectId nextent = AcUtils.EntNext(lastEnt);
                while(nextent != ObjectId.Null) {
                    idColl.Add(nextent);
                    nextent = AcUtils.EntNext(nextent);
                }

                Matrix3d transform = Matrix3d.Displacement(ppr.Value.UcsToWcs().GetAsVector());
                foreach(ObjectId id in idColl) {
                    ((Entity)tr.GetObject(id, OpenMode.ForWrite, true)).TransformBy(transform);
                }
                tr.Commit();
            }
        }
    }
    public static partial class Stuff
    {
        // CodeHimBelongaKwb ©  Feb 2008
        // transposed from MgdDbg by JIM AWE.
        //------------------------------------------------------------------
        // predefined values for common Points and Vectors
        public static readonly Point3d kOrigin = new Point3d(0.0, 0.0, 0.0);
        public static readonly Vector3d kXAxis = new Vector3d(1.0, 0.0, 0.0);
        public static readonly Vector3d kYAxis = new Vector3d(0.0, 1.0, 0.0);
        public static readonly Vector3d kZAxis = new Vector3d(0.0, 0.0, 1.0);
        //------------------------------------------------------------------
        /// <summary>
        /// shortcut for getting the current DWG's database
        /// </summary>
        /// <returns>Database for the current drawing</returns>
        public static Database  GetCurDwg()
        {
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            return db;
        }
        //------------------------------------------------------------------
        /// <summary>
        /// Get a transformed copy of a point from UCS to WCS
        /// </summary>
        /// <param name="pt">Point to transform</param>
        /// <returns>Transformed copy of point</returns>
        
        public static Point3d   UcsToWcs(this Point3d pt)
        {
            Matrix3d m = GetUcsMatrix(GetCurDwg());
            
            return pt.TransformBy(m);
        }            
        //------------------------------------------------------------------
/// <summary>
/// Is Paper Space active in the given database?
/// </summary>
/// <param name="db">Specific database to use</param>
/// <returns></returns>
public static bool IsPaperSpace(this Database db)
{
   System.Diagnostics.Debug.Assert(db != null);    
   if (db.TileMode)
       return false;
   
   Editor ed =  Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            if (db.PaperSpaceVportId == ed.CurrentViewportObjectId)
       return true;
       
   return false;
}
        //------------------------------------------------------------------
        /// <summary>
        /// Figure out the current UCS matrix for the given database.  If
        /// PaperSpace is active, it will return the UCS for PaperSpace.
        /// Otherwise, it will return the UCS for the current viewport in
        /// ModelSpace.
        /// </summary>
        /// <param name="db">Specific database to use</param>
        /// <returns>UCS Matrix for the specified database</returns>

        public static Matrix3d  GetUcsMatrix(Database db)
        {
            System.Diagnostics.Debug.Assert(db != null);

            Point3d origin;
            Vector3d xAxis, yAxis, zAxis;

            if(db.IsPaperSpace()) {
                origin = db.Pucsorg;
                xAxis = db.Pucsxdir;
                yAxis = db.Pucsydir;
            } else {
                origin = db.Ucsorg;
                xAxis = db.Ucsxdir;
                yAxis = db.Ucsydir;
            }
            zAxis = xAxis.CrossProduct(yAxis);
            return Matrix3d.AlignCoordinateSystem(kOrigin, kXAxis, kYAxis, kZAxis, origin, xAxis, yAxis, zAxis);
        }
        //------------------------------------------------------------------

    }
}
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kaefer

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #22 on: March 14, 2011, 08:34:08 AM »
Has anybody tried:

1. New 'side database'
2. DxfIn method on new 'side database' to insert dxf file into new pristine database
3. insert the new 'side database' with dxf info into current drawing

Yep, that works too. Incoming dialog.FileName, ppr.Value, par.Value, pdr.Value and then...
Code: [Select]
                    let mat =
                        Matrix3d.Scaling(pdr.Value, Point3d.Origin) *
                        Matrix3d.Rotation(par.Value, Vector3d.ZAxis, Point3d.Origin) *
                        Matrix3d.Displacement(ppr.Value - Point3d.Origin)
                   
                    use srcDb = new Database(false, true)
                    let tmpFileName = System.IO.Path.GetTempFileName()
                    srcDb.DxfIn(dialog.FileName, tmpFileName)
                    let srcMSpaceId = SymbolUtilityServices.GetBlockModelSpaceId srcDb

                    // Build ObjectIdCollection from objects to clone in source model space
                    use str = srcDb.TransactionManager.StartTransaction()
                    let sbtr = str.GetObject(srcMSpaceId, OpenMode.ForRead) :?> BlockTableRecord
                    let objIdColl = new ObjectIdCollection(sbtr |> Seq.cast |> Array.ofSeq)
                    str.Commit()

                    let map = new IdMapping()
                    db.WblockCloneObjects(objIdColl, db.CurrentSpaceId, map, DuplicateRecordCloning.Ignore, false)
               
                    // Sequence of ObjectIds in target database
                    let targetIds =
                         map
                         |> Seq.cast<IdPair>
                         |> Seq.choose
                            (fun pair ->
                                if pair.IsPrimary && pair.IsCloned then Some pair.Value else None
                            )
                   
                    // Transform objects in target current space
                    use tr = db.TransactionManager.StartTransaction()
                    for oid in targetIds do
                        (tr.GetObject(oid, OpenMode.ForWrite) :?> Entity).TransformBy mat
                    tr.Commit()

                    targetIds |> Array.ofSeq |> ed.SetImpliedSelection

Alas, the second DxfIn parameter logFilename is of little use, and it seems to stay open as long as the drawing session lasts.

Glenn R

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #23 on: March 14, 2011, 09:58:08 AM »
Isn't there a Database.Insert method that will accept your newly created dbase, rather than going through the whole cloning exercise? That's if I'm deciphering F#; wouldn't surprise me if I'm not as I don't do F#....
« Last Edit: March 14, 2011, 05:53:13 PM by Glenn R »

kaefer

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #24 on: March 14, 2011, 10:53:25 AM »
Isn't there a Databse.Insert method that will accept your newly created dbase,

Oh, my... of course there is!  The only trick that seems to be required is that the target model space should be opened for write.

Code: [Select]
                    ...
                    let mat =
                        Matrix3d.Scaling(pdr.Value, Point3d.Origin) *
                        Matrix3d.Rotation(par.Value, Vector3d.ZAxis, Point3d.Origin) *
                        Matrix3d.Displacement(ppr.Value - Point3d.Origin)
                   
                    use srcDb = new Database(false, false)
                    let tmpFileName = System.IO.Path.GetTempFileName()
                    srcDb.DxfIn(dialog.FileName, tmpFileName)
                    use tr = db.TransactionManager.StartTransaction()
                    tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId db, OpenMode.ForWrite) |> ignore
                    db.Insert(mat, srcDb, false) |> ignore
                    tr.Commit()

Quote
rather than going through the whole cloning exercise? That's if I'm deciphering F#; wouldn't surprise me if I'm not as I don't do F#....

That was exactly what I was trying accomplish. Doing OOP in F# is almost like C# without the nipple braces.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #25 on: March 14, 2011, 11:09:02 PM »
That was exactly what I was trying accomplish. Doing OOP in F# is almost like C# without the nipple braces.
:lmao: :lmao:

kaefer

  • Guest
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #26 on: March 15, 2011, 07:54:56 AM »
Something to play with :

Accounts Co-ordinate System other than WCS for insertion Point.

Thanks, Kerry.

May I borrow the GetUcsMatrix method as an extension property of Database?

Trying to wrap the whole thing up:

1. I think I'll stick with the WblockCloneObjects approach since it obviates collecting the objects manually, and it allows dumping them into current space.
2. It seems to be possible passing null as second parameter to Database.DxfIn. DXF import errors will cause exceptions, that's enough for error handling.
3. Just multiplicating the db.GetUcsMatrix return value with the transform generated out of insertion point, rotation and scaling arguments brings me UCS awareness.

For reference, the final F# code is appended.

Big thanks to all, Thorsten




Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #27 on: March 15, 2011, 08:50:45 AM »
< .. >
May I borrow the GetUcsMatrix method as an extension property of Database?

< .. >

sure

MgdDbg originally by Jim Awe from AutoDesk

This is the 2010 Version
http://through-the-interface.typepad.com/through_the_interface/2010/02/the-stephen-and-fenton-show-adn-devcast-episode-1.html
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #28 on: March 16, 2011, 08:21:00 PM »

Just to clarify the usage of GetUcsMatrix() as an extension method.
( for those following and in answer to PM mail)

If the GetUcsMatrix() is modified as follows by adding the this qualifier to the parameter list
( note that the fromOrigin, fromXAxis, fromYAxis, fromZAxis,  have also been modified to use a local definition
rather than  the public static readonly vars used previously, for the sake of simplicity.)

Code: [Select]
        //------------------------------------------------------------------
        /// <summary>
        /// Figure out the current UCS matrix for the given database.  If
        /// PaperSpace is active, it will return the UCS for PaperSpace.
        /// Otherwise, it will return the UCS for the current viewport in
        /// ModelSpace.
        /// </summary>
        /// <param name="db">Specific database to use</param>
        /// <returns>UCS Matrix for the specified database</returns>

        public static Matrix3d  GetUcsMatrix(this Database db)
        {
            System.Diagnostics.Debug.Assert(db != null);

            Point3d toOrigin;
            Vector3d toXAxis, toYAxis, toZAxis;

            if(db.IsPaperSpace()) {
                toOrigin = db.Pucsorg;
                toXAxis = db.Pucsxdir;
                toYAxis = db.Pucsydir;
            } else {
                toOrigin = db.Ucsorg;
                toXAxis = db.Ucsxdir;
                toYAxis = db.Ucsydir;
            }
            toZAxis = toXAxis.CrossProduct(toYAxis);
            return Matrix3d.AlignCoordinateSystem(
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis,
                toOrigin, toXAxis, toYAxis, toZAxis);
        }
        //------------------------------------------------------------------


The method can then be called by either :
Code: [Select]
Matrix3d m = GetUcsMatrix(GetCurDwg() );

Matrix3d m = GetUcsMatrix(db);

Matrix3d m = (GetCurDwg().GetUcsMatrix() );

Matrix3d m = (db.GetUcsMatrix() );
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VB.Net to Import/Insert a DXF File in Existing Drawing
« Reply #29 on: March 16, 2011, 08:25:29 PM »
< .. >
I'll do some more testing and report it to the ADN.


The Issue has a change request number allocated but don't expect any action soon unless someone can
Quote
provide a strong business case in order to increase the priority of a fix.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.