reverse command with parameter

reverse command with parameter

Anonymous
Not applicable
914 Views
4 Replies
Message 1 of 5

reverse command with parameter

Anonymous
Not applicable

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?

0 Likes
Accepted solutions (1)
915 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Are you expecting someone to guess what your

code is doing that may be causing the error?

0 Likes
Message 3 of 5

Anonymous
Not applicable

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);
        }

 

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

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).

 

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Many thanks!

0 Likes