.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Jig Insert Block

8 REPLIES 8
Reply
Message 1 of 9
coddy
935 Views, 8 Replies

Jig Insert Block

Hello,

In C#, can anybody give me some example code to insert a drawing as block using jig?

Thanks
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: coddy


Some time ago I found the following file on the
web: "DevTV - AutoCAD.NET Intro.wmv".

I remember there was something in it about jigs.
Could be what you're looking for.

P.S. If you can't stand guys who talk through their
nose and are reciting long strings of namespaces all the time, then don't look
at it.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello,
In C#, can anybody give me some example code to insert a drawing as block
using jig? Thanks
Message 3 of 9
Anonymous
in reply to: coddy


<P.S. If you can't stand guys who talk through
their nose and are reciting long strings of namespaces all the time, then don't
look at it.

 



style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">Huh...
So your logic is - if he is as intolerant of others as you are then don't bother
learning something from that person? Hope you don't

style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'">

style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">code
with that brain!

style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'">



style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"> 



style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'">
href="http://through-the-interface.typepad.com/through_the_interface/2007/05/using_a_jig_fro.html">...



style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">OP
- Try this link - Kean has other samples too. Also keep a notepad handy while
watching those videos mentioned as some have a strong
accent.

style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'">

style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">The
good part is the more you understand the api the easier it is to understand the
speakers’ different accents. I assume you will be bright enough to

style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'">

style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">understand
when the lecturer is fully qualifying his classes to make it easier for students
to understand what comes from where!

style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'">You
can obviously us a ‘using’ directive so you don’t have to fully qualify
everything in your own code.


 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Some time ago I found the following file on the
web: "DevTV - AutoCAD.NET Intro.wmv".

I remember there was something in it about jigs.
Could be what you're looking for.

P.S. If you can't stand guys who talk through
their nose and are reciting long strings of namespaces all the time, then
don't look at it.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello,
In C#, can anybody give me some example code to insert a drawing as block
using jig? Thanks
Message 4 of 9
coddy
in reply to: coddy

Kean's code is excellent and that is what I want too. But, this code is to insert a block that is already in the drawing. I would like to link this code to insert an external drawing and then insert the block with jig. Can this be accomplished?

Thanks
Message 5 of 9
Anonymous
in reply to: coddy


I don't have an example but I'd be there is one on
Kean's site for inserting a drawing. You can do some testing

of combining that with the jig
examples.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Kean's
code is excellent and that is what I want too. But, this code is to insert a
block that is already in the drawing. I would like to link this code to insert
an external drawing and then insert the block with jig. Can this be
accomplished? Thanks
Message 6 of 9
coddy
in reply to: coddy

I did so, but sends out "Insertion Point" command twice. How do I go about it?

[CommandMethod("test")]
public void test()
{
string fName=@"C:\a.dwg";

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
//Get the editor object
Editor ed = doc.Editor;

string blkName="a";

//Get the working database
Database dwg = doc.Database;

//Start a transaction
Transaction tr = doc.TransactionManager.StartTransaction();

try
{
//Create temporary database to read in block
Database dbDwg = new Database();

//Read the file from disk
dbDwg.ReadDwgFile(fName, System.IO.FileShare.Read, true, "");

//Insert it into the current database.
dwg.Insert(blkName, dbDwg, false);

dbDwg.Dispose();

//Open the block for read.
BlockTable bt = (BlockTable)tr.GetObject(dwg.BlockTableId, OpenMode.ForRead);

//See if the block table record exists
if (bt.Has(blkName))
{
//Prompt user for insertion point
PromptPointOptions po = new PromptPointOptions("Select insertion point: ");

//Get user to select the insertion point
PromptPointResult pr = ed.GetPoint(po);

//user selected a valid point
if (pr.Status == PromptStatus.OK)
{
//fix up the point to be a Point3D object
Point3d pt = new Point3d(pr.Value.X, pr.Value.Y, pr.Value.Z);

ObjectId bId = bt[blkName];

//insert the block at the insertion point
BlockReference br = new BlockReference(pt, bId);

BlockJig blkJig = new BlockJig(br);

//Perform the jig operation
pr =(PromptPointResult) ed.Drag(blkJig);

if (pr.Status == PromptStatus.OK)
{
//Add block reference to the current space
BlockTableRecord curSpace = (BlockTableRecord)tr.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite);

//Add the block reference to the current space
curSpace.AppendEntity(blkJig.GetEntity());

//Tell the transaction
tr.AddNewlyCreatedDBObject(blkJig.GetEntity(), true);

//Commit transaction to database
tr.Commit();
}
}
else
{
MessageBox.Show("Block " + blkName + " does not exists");
}
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
//Always dispose of transaction
tr.Dispose();
}

}

Thanks

Edited by: coddy on Feb 10, 2009 7:36 AM Edited by: coddy on Feb 10, 2009 7:39 AM
Message 7 of 9
Anonymous
in reply to: coddy


If you cannot get it to work you could just insert
the drawing and then jig the block in two seperate steps.

I have not tried to jig an external drawing so I'm
not sure it you can or not.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
did so, but sends out "Insertion Point" command twice. How do I go about it?
[CommandMethod("test")] public void test() { string fName=@"C:\a.dwg";
Document doc =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
//Get the editor object Editor ed = doc.Editor; string blkName="a"; //Get the
working database Database dwg = doc.Database; //Start a transaction
Transaction tr = doc.TransactionManager.StartTransaction(); try { //Create
temporary database to read in block Database dbDwg = new Database(); //Read
the file from disk dbDwg.ReadDwgFile(fName, System.IO.FileShare.Read, true,
""); //Insert it into the current database. dwg.Insert(blkName, dbDwg, false);
dbDwg.Dispose(); //Open the block for read. BlockTable bt =
(BlockTable)tr.GetObject(dwg.BlockTableId, OpenMode.ForRead); //See if the
block table record exists if (bt.Has(blkName)) { //Prompt user for insertion
point PromptPointOptions po = new PromptPointOptions("Select insertion point:
"); //Get user to select the insertion point PromptPointResult pr =
ed.GetPoint(po); //user selected a valid point if (pr.Status ==
PromptStatus.OK) { //fix up the point to be a Point3D object Point3d pt = new
Point3d(pr.Value.X, pr.Value.Y, pr.Value.Z); ObjectId bId = bt[blkName];
//insert the block at the insertion point BlockReference br = new
BlockReference(pt, bId); BlockJig blkJig = new BlockJig(br); //Perform the jig
operation pr =(PromptPointResult) ed.Drag(blkJig); if (pr.Status ==
PromptStatus.OK) { //Add block reference to the current space BlockTableRecord
curSpace = (BlockTableRecord)tr.GetObject(dwg.CurrentSpaceId,
OpenMode.ForWrite); //Add the block reference to the current space
curSpace.AppendEntity(blkJig.GetEntity()); //Tell the transaction
tr.AddNewlyCreatedDBObject(blkJig.GetEntity(), true); //Commit transaction to
database tr.Commit(); } } else { MessageBox.Show("Block " + blkName + " does
not exists"); } } } catch (System.Exception ex) {
MessageBox.Show(ex.ToString()); } finally { //Always dispose of transaction
tr.Dispose(); } } Thanks Edited by: coddy on Feb 10, 2009 7:36 AM Edited by:
coddy on Feb 10, 2009 7:39 AM
Message 8 of 9
coddy
in reply to: coddy

In fact, the code is working, but I'm looking to multiply insert blocks which I cannot get to work.
Message 9 of 9
Anonymous
in reply to: coddy



Does this not do it? If you cannot get it to work
post your entire code in a .cs file and some will

have a look for you. I cannot until
Friday.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
In
fact, the code is working, but I'm looking to multiply insert blocks which I
cannot get to work.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost