Hello Everyone,
In my current task I had wrote some code to Automate drawing (GA Drawing in AutoCAD electrical(2018) using C# .NET ).
The Code looks as attached .
As per code, The Main command is "GenerateSchematicDrawingforFETest". while calling this command.
The "TestGA" command is run some time and some time it's not run.
I am not get why this happen.
I observe one thing the while using "TESTGA" the CPU usage is high up to 90-99% can this affect to run a command?
Please suggest any improvement or modification in code.
[CommandMethod("GenerateSchematicDrawingforFE", CommandFlags.Modal | CommandFlags.Session)]
public void GenerateSchematicDrawingforFE()
{
// Some code to read drawingFilesList)
foreach (string drawingFile in drawingFilesList)
{
//Check and Open Dwg File
string fileFullName = projectPath + drawingFile;
Document curDwg = null;
// DocumentLock lockDoc = curDwg.LockDocument();
if (drawingFile != null )
{
curDwg = OpenDrawing(fileFullName);
if (curDwg != null)
acaddoc = Application.DocumentManager.MdiActiveDocument.GetAcadDocument() as AcadDocument;
//This Command is run completely some time or some time not
acaddoc.SendCommand("TestGA\r\n");
acaddoc.Close();
acaddoc = null;
}
}
}
public Document OpenDrawing(string dwgFileName)
{
//string strFileName = "C:\\campus.dwg";
DocumentCollection acDocMgr = Application.DocumentManager;
if (File.Exists(dwgFileName))
{
Document dwgFile = acDocMgr.Open(dwgFileName, false);
//dwgFile.IsActive = true;
Application.DocumentManager.MdiActiveDocument = dwgFile;
//dwgFile.CloseAndSave(dwgFile.Name);
if (dwgFile.IsActive)
{
return dwgFile;
}
else
{
return dwgFile;
}
}
else
{
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + dwgFileName +
" does not exist.");
return null;
}
}
[CommandMethod("TestGA")]
public void TestGA()
{
ReadExcelFile(); //Collect GA Data from excel
BomGenerator generator = new BomGenerator();
List<PanelComponant> panelForSheet = null;
try
{
var NamplateXmlDATA = ProjectData.requestDetails;
foreach (var item in ProjectData.GACoOrdinateData)
{
if (item.Key.StartsWith(CurrentGASheetNumber))
{
//1. Get all excel sheet data of current GA drawing.
panelForSheet = generator.GetEachSheetDataInList(item.Key);
//panelForSheet = panelForSheet.OrderBy(m => Convert.ToInt32(m.Order.Trim())).ToList();
foreach (var componant in panelForSheet)
{
switch (componant.BlockType.ToUpper())
{
case "STATIC":
case "DYNAMIC":
case "KIT":
LispInsertComponent(componant);
break;
case "TEXT":
CreateText(componant);
break;
}
}
break;
}
}
}
catch (System.Exception EX)
{
}
}
Thank you,
Dinesh Pawar
Hello Everyone,
In my current task I had wrote some code to Automate drawing (GA Drawing in AutoCAD electrical(2018) using C# .NET ).
The Code looks as attached .
As per code, The Main command is "GenerateSchematicDrawingforFETest". while calling this command.
The "TestGA" command is run some time and some time it's not run.
I am not get why this happen.
I observe one thing the while using "TESTGA" the CPU usage is high up to 90-99% can this affect to run a command?
Please suggest any improvement or modification in code.
[CommandMethod("GenerateSchematicDrawingforFE", CommandFlags.Modal | CommandFlags.Session)]
public void GenerateSchematicDrawingforFE()
{
// Some code to read drawingFilesList)
foreach (string drawingFile in drawingFilesList)
{
//Check and Open Dwg File
string fileFullName = projectPath + drawingFile;
Document curDwg = null;
// DocumentLock lockDoc = curDwg.LockDocument();
if (drawingFile != null )
{
curDwg = OpenDrawing(fileFullName);
if (curDwg != null)
acaddoc = Application.DocumentManager.MdiActiveDocument.GetAcadDocument() as AcadDocument;
//This Command is run completely some time or some time not
acaddoc.SendCommand("TestGA\r\n");
acaddoc.Close();
acaddoc = null;
}
}
}
public Document OpenDrawing(string dwgFileName)
{
//string strFileName = "C:\\campus.dwg";
DocumentCollection acDocMgr = Application.DocumentManager;
if (File.Exists(dwgFileName))
{
Document dwgFile = acDocMgr.Open(dwgFileName, false);
//dwgFile.IsActive = true;
Application.DocumentManager.MdiActiveDocument = dwgFile;
//dwgFile.CloseAndSave(dwgFile.Name);
if (dwgFile.IsActive)
{
return dwgFile;
}
else
{
return dwgFile;
}
}
else
{
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + dwgFileName +
" does not exist.");
return null;
}
}
[CommandMethod("TestGA")]
public void TestGA()
{
ReadExcelFile(); //Collect GA Data from excel
BomGenerator generator = new BomGenerator();
List<PanelComponant> panelForSheet = null;
try
{
var NamplateXmlDATA = ProjectData.requestDetails;
foreach (var item in ProjectData.GACoOrdinateData)
{
if (item.Key.StartsWith(CurrentGASheetNumber))
{
//1. Get all excel sheet data of current GA drawing.
panelForSheet = generator.GetEachSheetDataInList(item.Key);
//panelForSheet = panelForSheet.OrderBy(m => Convert.ToInt32(m.Order.Trim())).ToList();
foreach (var componant in panelForSheet)
{
switch (componant.BlockType.ToUpper())
{
case "STATIC":
case "DYNAMIC":
case "KIT":
LispInsertComponent(componant);
break;
case "TEXT":
CreateText(componant);
break;
}
}
break;
}
}
}
catch (System.Exception EX)
{
}
}
Thank you,
Dinesh Pawar
Can't find what you're looking for? Ask the community or share your knowledge.