.NET

Reply
Mentor
mgorecki
Posts: 414
Registered: ‎09-23-2004
Message 1 of 9 (329 Views)

Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

329 Views, 8 Replies
01-09-2012 12:19 PM

Ok, I have code that works just fine in AutoCad 2010 (just plain ol' AutoCad), but will not run completely in AutoCad Mechanical 2012.  The code will draw lines, arcs, circle, plines, etc. as well as insert blocks.  The command to insert the block has the entire block path so I don't have to rely on setting that up for everyone.

In AutoCad Mechanical only the blocks show up.  No lines, arcs or anything else is drawn.  I do not use a command method (like in LiSP) to create those objects, I create them through the block table and block table records.

What do I have to do to get my code to run in AutoCad Mechanical 2012?

 

Thanks,

Mark

ADN Support Specialist
adam.nagy
Posts: 610
Registered: ‎03-26-2007
Message 2 of 9 (286 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-10-2012 05:13 PM in reply to: mgorecki

Hi there,

 

Are you saying that even the most basic commands like the one below that adds a line has no effect in your AutoCAD Mechanical 2012? :-s

Did you debug into the code?

Did you check if the added entities were inside the database? - e.g. using ArxDbg (part of the ObjectARX SDK samples)

 

<code>

    [CommandMethod("drawline")]

    static public void drawline()

    {

      Database db = HostApplicationServices.WorkingDatabase;

  

      using (Transaction tr = db.TransactionManager.StartTransaction())

      {

        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

        BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

 

        Line ln = new Line(new Point3d(10, 10, 0), new Point3d(20, 20, 0));

        ms.AppendEntity(ln);

        tr.AddNewlyCreatedDBObject(ln, true);

 

        tr.Commit(); 

      }

    }

</code>

 

Cheers,

Adam Nagy

Developer Techincal Services



Adam Nagy
Developer Technical Services
Autodesk Developer Network
Mentor
SENL1362
Posts: 212
Registered: ‎07-20-2011
Message 3 of 9 (271 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-11-2012 12:23 AM in reply to: mgorecki

Is it a display issue, i.e. can you select the entities (^A). 

What does the STATUS command tell you ?

Layer filters ?

Tried to AUDIT and or RECOVER ?

 

Mentor
mgorecki
Posts: 414
Registered: ‎09-23-2004
Message 4 of 9 (257 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-11-2012 07:02 AM in reply to: adam.nagy

Hello Adam,

The code I use is similar to that.  Also, the program hangs every time it's run.  My AutoCad session just says "Not responding" after inserting the blocks.  It wont let me check on anything alse because of this lock up.

 

Mark

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 9 (252 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-11-2012 09:52 AM in reply to: mgorecki

Try set CommandFlags.Session and

wrap code into :

Using LockDocument

'insert block here

End Using

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mgorecki
Posts: 414
Registered: ‎09-23-2004
Message 6 of 9 (238 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-11-2012 02:56 PM in reply to: Hallex

I'm not sure what you mean.  I don't think I ever used "Using LockDocument" or "CommandFlags.Session".  Can you explain it more?

 

Thanks

Mentor
SENL1362
Posts: 212
Registered: ‎07-20-2011
Message 7 of 9 (229 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-11-2012 11:21 PM in reply to: mgorecki

Good idea of Hallex but if that would be the problem how is that different for Vanilla AutoCAD ?

 

[CommandMethod("MyCommand", CommandFlags.Session)]
public static void MyCommand()

{

    using (DocumentLock dl =Application.DocumentManager.MdiActiveDocument.LockDocument())
    {

           //do your thing
    }

}

 

Mentor
mgorecki
Posts: 414
Registered: ‎09-23-2004
Message 8 of 9 (207 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-17-2012 07:00 AM in reply to: SENL1362

I tried using the lockducument and commandflags.session as suggested, but it still did not work.

 

Best regards,

Mark

*Expert Elite*
Alfred.NESWADBA
Posts: 9,400
Registered: ‎06-29-2007
Message 9 of 9 (191 Views)

Re: Code Works in Vanilla AutoCad 2010, But Not in AutoCad Mechanical 2012

01-18-2012 12:49 AM in reply to: mgorecki

Hi,

 

You answered the message from Adam with

>> The code I use is similar to that.  Also, the program hangs every time it's run

That was not what he asked for (imho). You should really try to create a new solution, use his code in this solution and let him know it that has the same problem.

 

To just say "I did it in the same way" is not the option to isolate your problem because his code works for others and if it does not work on your pc then you know that something is wrong with your installation or with your solution/prroject settings. If it works you have two sultions where you can start to compare. That's where to start.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!