Author Topic: how to make a qnew command in C#.  (Read 2802 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
how to make a qnew command in C#.
« on: July 30, 2014, 01:43:18 PM »
I know how to open a saved dwg file and can open an Acad.dwt file
but how does one go about creating a new dwg and open it as you would by using the "Qnew command"?

I'm using SDI = 0 so the following throws an error.
I'm using SDI = 1 so the following throws an error. Edited: 7/31/14 bz

Code: [Select]
DocumentCollection acDocMgr = AcadApp.DocumentManager;
          Document acDoc = acDocMgr.Add(strTemplatePath);
          acDocMgr.MdiActiveDocument = acDoc;

i've done a lot of searching but can't find anything that will work for me.
« Last Edit: July 31, 2014, 12:17:47 PM by BillZndl »

BillZndl

  • Guest
Re: how to make a qnew command in C#.
« Reply #1 on: July 30, 2014, 02:44:18 PM »
Found a way to do it that i should've know but forgot over time.

Code: [Select]
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
         Database db = doc.Database;
         doc.SendStringToExecute("QNew ", true, false, false);

I'm writing an old App from Autolisp -> C#.
The code is behind a button.

Thanks anyways!

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: how to make a qnew command in C#.
« Reply #2 on: July 30, 2014, 04:50:15 PM »

Code - C#: [Select]
  1. DocumentCollection acDocMgr = AcadApp.DocumentManager;
  2. Document acDoc = acDocMgr.Add(strTemplatePath);
  3. acDocMgr.MdiActiveDocument = acDoc;

I have SDI = 0 and the code works for me.  Been using it since 2012 as an plugin to create files from specific templates.  The code is implemented as a command that is then called from a ribbon button.


Here is a snippet of the class that has some of the commands that are working.


Code - C#: [Select]
  1. [CommandMethod("NewFromTemplatePipeSpoolUSImperial", CommandFlags.Session)]
  2. public static void CommandNewFromTemplatePipeSpoolUsImperial()
  3. {
  4.         CreateDrawing("Spool Template (US Imperial).dwt");
  5. }
  6.  
  7.  
  8. [CommandMethod("NewFromTemplateDuctSpoolUSImperial", CommandFlags.Session)]
  9. public static void CommandNewFromTemplateDuctSpoolUsImperial()
  10. {
  11.         CreateDrawing("Duct Spool Template (US Imperial).dwt");
  12. }
  13.  
  14.  
  15. [CommandMethod("NewFromTemplateParametricPartWizardUSImperial", CommandFlags.Session)]
  16. public static void CommandNewFromTemplateParametricPartWizardUsImperial()
  17. {
  18.         CreateDrawing("Parametric Part Wizard Template (US Imperial).dwt");
  19. }
  20.  
  21.  
  22. private static void CreateDrawing(string fileName)
  23. {
  24.         DocumentCollection acDocMgr = Application.DocumentManager;
  25.         Document acDoc = acDocMgr.Add(fileName);
  26.         acDocMgr.MdiActiveDocument = acDoc;
  27. }




I have other code that makes sure the templates are in my support path so that AutoCAD can find them.
« Last Edit: July 30, 2014, 04:54:32 PM by Keith Brown »
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

BillZndl

  • Guest
Re: how to make a qnew command in C#.
« Reply #3 on: July 31, 2014, 06:24:31 AM »

Code - C#: [Select]
  1. DocumentCollection acDocMgr = AcadApp.DocumentManager;
  2. Document acDoc = acDocMgr.Add(strTemplatePath);
  3. acDocMgr.MdiActiveDocument = acDoc;

I have SDI = 0 and the code works for me.  Been using it since 2012 as an plugin to create files from specific templates.  The code is implemented as a command that is then called from a ribbon button.


Opps, fat fingered that one, I meant I was using SDI = 1.
The error said the command was not available in SDI = 1 mode.


Keith Brown

  • Swamp Rat
  • Posts: 601
Re: how to make a qnew command in C#.
« Reply #4 on: July 31, 2014, 09:50:06 AM »
Opps, fat fingered that one, I meant I was using SDI = 1.
The error said the command was not available in SDI = 1 mode.


That makes sense then.   :D
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013