How to add Block in Bricsys using C#
I need to open the bricsys file and insert the block into this. How I can implement this
[code]
private void ObjectInsert()
{
//BricscadApp.AcadApplication oACAD = new BricscadApp.AcadApplication();
//BricscadApp.AcadDocument oACADdoc = default(BricscadApp.AcadDocument);
BricscadApp.AcadApplication oACAD = default(BricscadApp.AcadApplication);
BricscadApp.AcadDocument oACADdoc = default(BricscadApp.AcadDocument);
oACAD = (BricscadApp.AcadApplication)Interaction.GetObject("", "BricscadApp.AcadApplication");
//oACAD.Documents.Add("D:\\Dwg Template.dwg");
oACADdoc = oACAD.Documents.Open("D:\\object insert.dwg");
oACADdoc = oACAD.ActiveDocument;
double rot = 0;
double rot2 = 0;
double x = 0;
double y = 0;
double x1 = 0;
double y1 = 0;
double x2 = 0;
double y2 = 0;
jump5:
if (Hydsitelocator == 0)
goto jump6;
switch (Convert.ToInt32(Hydsitelocator))
{
case 21:
x = Hydrant;
y = streetwidth2 / 2 + 24;
break;
case 22:
x = Hydrant;
y = -streetwidth2 / 2 - 24;
break;
case 12:
x = -streetwidth1 - 24.0;
y = Hydrant + streetwidth2 / 2;
break;
case 11:
x = 24.0;
y = Hydrant + streetwidth2 / 2;
break;
case 31:
x = Blockend - 24.0;
y = Hydrant + streetwidth2 / 2;
break;
case 32:
x = Blockend + 24.0 + streetwidth3;
y = Hydrant + streetwidth2 / 2;
break;
case 42:
x = Hydrant;
y = Blockendy + streetwidth4 + streetwidth2 / 2 + 24.0;
break;
case 41:
x = Hydrant;
y = Blockendy - 24.0 + streetwidth2 / 2;
break;
case -21:
x = Blockend - Hydrant;
y = streetwidth2 / 2 + 24;
break;
case -22:
x = Blockend - Hydrant;
y = -streetwidth2 / 2 - 24;
break;
case -12:
x = -streetwidth1 - 24.0;
y = Blockendy - Hydrant + streetwidth2 / 2;
break;
case -11:
x = 24.0;
y = Blockendy - Hydrant + streetwidth2 / 2;
break;
case -31:
x = Blockend - 24.0;
y = Blockendy - Hydrant + streetwidth2 / 2;
break;
case -32:
x = Blockend + 24.0 + streetwidth3;
y = Blockendy - Hydrant + streetwidth2 / 2;
break;
case -42:
x = Blockend - Hydrant;
y = Blockendy + streetwidth4 + streetwidth2 / 2 + 24.0;
break;
case -41:
x = Blockend - Hydrant;
y = Blockendy - 24.0 + streetwidth2 / 2;
break;
}
InsertionPoint[0] = x;
InsertionPoint[1] = y;
InsertionPoint[2] = 0;
BricscadDb.IAcadBlock objectBloackHYDRANT;
objectBloackHYDRANT = oACADdoc.Blocks.Add(InsertionPoint, "surveyorHYDRANT");
BricscadDb.AcadBlockReference BlockHYDRANT = default(BricscadDb.AcadBlockReference);
BlockHYDRANT = oACADdoc.ModelSpace.InsertBlock(InsertionPoint, "surveyorHYDRANT", 1, 1, 1, 0);
BlockHYDRANT.Update();
}
[/code]
Thanks in Advance
Comments
-
maybe this sample will help you.
[code]
using System;
using System.Linq;
using System.Collections.Generic;
//alias
using AcRx = Teigha.Runtime;
using AcDb = Teigha.DatabaseServices;
using AcAp = Bricscad.ApplicationServices;
using AcEd = Bricscad.EditorInput;
using AcGe = Teigha.Geometry;
using AcWn = Bricscad.Windows;
using AcApX = BricscadApp;
using AcDbX = BricscadDb;
[assembly: AcRx.CommandClass(typeof(BcadMgdTest.Commands))]
namespace BcadMgdTest
{
public static class Commands
{
[AcRx.CommandMethod("doit")]
public static void doit()
{
try
{
string srcname = @c:\temp\mickey.dwg;
string destname = @c:\temp\test.dwg;
AcApX.AcadApplication appX =
AcAp.Application.AcadApplication as AcApX.AcadApplication;
AcApX.AcadDocument curDoc = appX.ActiveDocument;
AcApX.AcadDocument destDoc = appX.Documents.Open(destname, false, null);
destDoc.Activate();
destDoc.ModelSpace.InsertBlock(new double[] { 0, 0, 0 }, srcname, 1, 1, 1, 0, null);
destDoc.Save();
destDoc.Close(true,destname);
curDoc.Activate();
}
catch (System.Exception ex)
{
AcAp.Application.ShowAlertDialog(
string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
}
}
}
}
[/code]
Cheers : )
0 -
Thanks for reply!
Can you please tell me how I can use this 'Teigha' I mean from where I can get the dll of this, because I am getting error while add following :
using AcRx = Teigha.Runtime;
Error:
The type or namespace name 'Teigha' could not be found(are you missing a using directive or an assembly reference? )
Thanks and Regards!
SSD0 -
Are you intending to run this code inside Bricscad? or out of process in an .EXE?
0 -
Running the code inside BricsCAD works perferct , but no luck running the insertblock from out of process EXE .After successfully launching the application, I get error message that BricsCAD Application has stopped working. I can do other stuffs like adding lines but inserting block is a pain in the neck. Please help.Here's my codeusing AcAp = Bricscad.ApplicationServices;
using AcApX = BricscadApp;private void BricsCADApp()
{
BricscadApp.AcadApplication cadApp = new BricscadApp.AcadApplication();
try
{
cadApp = (BricscadApp.AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("BricscadApp.AcadApplication");
cadApp.Visible = true;
AcApX.AcadDocument ThisDrawing = cadApp.ActiveDocument;string path = @C:\TEST\TBLOCK.DWG;
double[] insPt = new double[] { 0, 0, 0 };
ThisDrawing.ModelSpace.InsertBlock(insPt, path, 1, 1, 1, 90, null);cadApp.ZoomExtents();
}
catch (System.Exception)
{
throw;
}
}0