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

reverse command with parameter

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
flovo
640 Views, 4 Replies

reverse command with parameter

I need to use autocad reverse command in c# .net with a polyline as a parameter.

I used http://www.caddzone.com/CommandLine.cs without success getting InvalidOperationException.

How can I do?

4 REPLIES 4
Message 2 of 5
caddzone
in reply to: flovo

Are you expecting someone to guess what your

code is doing that may be causing the error?



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 5
flovo
in reply to: flovo

Sorry,

I use:

 

public void FirstCheck()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            LayerTable acLyrTbl = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
            BlockTable bt = (BlockTable)tr.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);
            BlockTableRecord btr = (BlockTableRecord)tr.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);
            using (tr)
            {
                foreach (ObjectId asObjId in btr)
                {
                    DBObject obj = tr.GetObject(asObjId, OpenMode.ForRead);
                    Entity ent = obj as Entity;
                    if (asObjId.ObjectClass.DxfName.CompareTo("LWPOLYLINE") == 0)
                    {
                        Polyline lwp = obj as Polyline;
                        decimal Area = (decimal)PlineAlgebraicArea(lwp);
                        if (Area > 0)
                        {
                            CommandLine.Reverse(lwp);
                        }
                    }
                }
                tr.Commit();
            }
        }

 

 

where CommandLine is http://www.caddzone.com/CommandLine.cs with added:

 

  public static int Reverse(Polyline lwp)
        {
            return Command("_REVERSE ", lwp);
        }

 

Message 4 of 5
caddzone
in reply to: flovo

That's better.

 

Before you run commands on objects, you should commit

the transaction you got them from.

 

In the version of CommandLine.cs that you have, DBObjects

cannot be passed to Command(), only their ObjectIds can be

passed.  A new version of CommandLine.cs is in the works

that supports passing an Entity or its ObjectId, but that's not

ready yet.

 

So, after you commit the transaction you get the polyline from,

you just pass its ObjectId to Command() rather than the Polyline

itself.

 

Also, i see you've added a Reverse() method to the CommandLine

class. While there's no problem with doing that, You don't really

have to, you can just calll Command() directly like this:

 


CommandLine.Command( "._REVERSE", asObjId, "" );

 

Lastly, you may be able to reverse a polyline without having

to use the command line. The PolyLine class has a ReverseCurve()

method (not sure what release that showed up in, so it may

not be in the releases you're targeting).

 

 



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 5 of 5
flovo
in reply to: flovo

Many thanks!

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