Author Topic: Cannot Enter Command After the First Time Using Fabrication API  (Read 98 times)

0 Members and 1 Guest are viewing this topic.

Offline jaysomlamTopic starter

  • Full Member
  • ***
  • Posts: 144
  • Country: us
  • Gender: Male
I have a very strange problem.  After my program uses Fabrication API to prepare a list of Object-IDs (to select duct), I find that I cannot type in any command in AutoCAD any more.  This is like the input focus has been moved away to some place else (no idea where it goes).  The cross-hair in the model space disappears.  I have to click in the model space or in the AutoCAD command line before I can type command (this seems to allow AutoCAD to regain input focus).  After this problem has happened once, it won't happen again until next time I re-launch CADmep.

On the other hand, if I use regular AutoCAD API to prepare a list of Object-IDs of any item on the drawing, I don't have this problem.  This problem only occurs when I use Fabrication API to prepare a list of Object-IDs of duct.

This happens regardless if I run the program under the debugger or not.

This happens regardless if the program selects the duct or not.  What triggers the problem is the use of Fabrication API to prepare the list of Object-IDs of duct items.

The following two programs show the problem (one has the problem, the other doesn't):

Code: [Select]
[CommandMethod("MyLib_SelectAllAdskFabItems")]
public void SelectAllAdskFabItems()
   // This program selects all the Autodesk Fabrication Items.
   // Note: This triggers the problem after first time it runs. No problem subsequently.
   {
   Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
   Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;

   List<ObjectId> lisAdskFabItems = new List<ObjectId>();
   foreach( Item itm in Job.Items )
      {
      String   sCurItemHandle = Job.GetACADHandleFromItem( itm );
      long     lCurItemHandle = Convert.ToInt64( sCurItemHandle, 16 );
      Handle   hCurItem       = new Handle( lCurItemHandle );
      ObjectId idCurItemObj   = db.GetObjectId( false, hCurItem, 0 );
      lisAdskFabItems.Add( idCurItemObj );
      }

   // The problem will occur regardless the program selects the duct in the list or not.
   Autodesk.AutoCAD.Internal.Utils.SelectObjects( lisAdskFabItems.ToArray() );
   }

[CommandMethod("MyLib_SelectAllObjects")]
public void SelectAllObjects()
   // This program selects all the objects on the drawing.
   // Note: This doesn't have the problem.
   {
   Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
   Editor   ed  = doc.Editor;
   PromptSelectionResult resPromptObj = ed.SelectAll();

   List<ObjectId> lisAllObjs = new List<ObjectId>();

   SelectionSet ssObj = resPromptObj.Value;
   foreach( SelectedObject oObj in ssObj )
      {
      lisAllObjs.Add( oObj.ObjectId );
      }

   Autodesk.AutoCAD.Internal.Utils.SelectObjects( lisAllObjs.ToArray() );
   }

The following is the steps to trigger the problem:
  • Create a drawing with a few CADmep duct.
  • Launch CADmep and open that drawing.
  • NETLOAD the program
  • Leave the cross-hair in the model space.
  • Type the command to run "MyLib_SelectAllAdskFabItems".
  • See that all the duct are selected.  But the cross-hair disappears.
  • Type any command and AutoCAD ignores it.

Would you please tell me how to fix this problem?  Thanks.

Jaysom

Online DotNet

  • Full Member
  • ***
  • Posts: 55
  • Country: us
  • Gender: Male
Re: Cannot Enter Command After the First Time Using Fabrication API
« Reply #1 on: Dec 06, 2018, 02:18:24 PM »
CADmep is in "view only mode" until a command or the API invokes CADmep for the first time. When that happens your license is checked and CADmep's Intitialize method is ran. Regular AutoCAD commands and the AutoCAD API will work just fine, only commands or API specific to CADmep will invoke it's Initialize method. Run a CADmep command and wait for it to complete before you do anything with the API.
« Last Edit: Dec 06, 2018, 02:25:34 PM by DotNet »

Offline jaysomlamTopic starter

  • Full Member
  • ***
  • Posts: 144
  • Country: us
  • Gender: Male
Re: Cannot Enter Command After the First Time Using Fabrication API
« Reply #2 on: Dec 06, 2018, 04:44:18 PM »
Thanks for explaining why this problem occurs.  Now I would like to see if there is a workaround.

I have tried running Fabrication API in an async/await routine immediately upon launching my program.  But the problem is still there.

I manually run JOBINFO (a CADmep command) right after launching CADmep, and immediately exit from JOBINFO dialog box, and I find that I encounter the same problem (cannot type in any command).

Seem like there is no way to get around this problem.  This is just a matter of whether the user manually triggers the problem through issuing a CADmep command, or running my program that uses Fabrication API.  The problem will already be there.  Do I understand this correctly?

Jaysom

Online DotNet

  • Full Member
  • ***
  • Posts: 55
  • Country: us
  • Gender: Male
Re: Cannot Enter Command After the First Time Using Fabrication API
« Reply #3 on: Dec 06, 2018, 04:59:40 PM »
I would use a more subtle command like ATTACHOFF. Maybe try this after the command is finished:

Code: [Select]
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();

Offline jaysomlamTopic starter

  • Full Member
  • ***
  • Posts: 144
  • Country: us
  • Gender: Male
Re: Cannot Enter Command After the First Time Using Fabrication API
« Reply #4 on: Dec 07, 2018, 01:06:19 PM »
Thanks the SetFocusToDwgView() command gets around this problem.  This means I need to call that command at the end of any of my command that needs to use Fabrication API or CADmep command.  Glad that there is a way to fix this problem.  I consider this issue as solved.

Jaysom