AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inserting blocks without using jigs

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Anonymous
770 Views, 9 Replies

Inserting blocks without using jigs

How can I insert a block with attributes using VB.net without using jigs? Currently Jigs requires a PromptResult and I want to just pass the block name and attribute without having to respond to the PromptResult.

Tags (2)
9 REPLIES 9
Message 2 of 10
dohenry
in reply to: Anonymous

Hi rhaywood

 

I done some work with inserting blocks with Attributes some time ago.  

 

Can you expand a bit more on what you need and mean by jigs?

 

Are you creating the block definition (attributes) in code or only inserting the block and populating the Attributes using code?

 

Message 3 of 10
Anonymous
in reply to: dohenry

It appears that the only way to insert a block (with or without attributes) and be able to rotate it is by using jigs. I could insert but not be able to rotate the block on the fly.
The blocks already exist. This is a menu driven app for inserting various blocks, some with and some without attributes, but it is essential to rotate them. My code works fine with the jigs, but it requires a PromptResult. I already know what the block name is and I want to just pass it, but I have to confirm it which is an unnecessary step and confusing to the user. You can't just say PromptResult is true and pass the block name or if you can I haven't figured it out.
Does this help?
Rod
Message 4 of 10
dohenry
in reply to: Anonymous

Hi Rod

 

I not sure if I can help you.

 

I don't have any experience of jigs if that the problem?

 

I run code either from the command prompt calling a saved procedure or using a load Form.

 

I calling up the insertion of the blocks using a Vb.Net insertion procedure and don't get any PromptResult.

 

So not sure where you are getting the PropmptResult is it coming from the Attributes? 

 

If you insert the block manually do you PropmptResult?

 

 

 

 

 

Message 5 of 10
norman.yuan
in reply to: Anonymous

Block can definitely be inserted proggrammatically without Jig, if it is not necessary for waiting user input. Mind you, jig is meant to provide visual hint when the process (inserting) is waiting for user input (position, rotation, scale...), thus the inserting can only be completed(or cancelled) after PropmtResult is returned, when jig is used.

 

So, I am not quite sure what you want: do you mean that your code can insert a block, but cannot rotate it to a known angle without jig? If the rotation angle is known (or any other inserting data, position, scale...) why there is need for jig? 

 

For example, if all information about inserting a block is known, you can do the inserting like (pseudo-code)

 

public void InsertBlock(string blkName, Point3d position, double rotation, doubel scale)

{

    //Find block definition id, based on block name. insert the block definition, if necessary

    ....

 

    //Create block referenece

    var bref=new BlockReference(blkdefId, position);

    // add it to proper space (model or paper)

    // add to transaction 

 

    //Add attributes, if necessary, based on block defeinition

 

   //Roate it to the known angle (WITHOUT waiting for user input via jig!)

    var mt = Matrix3D.Rotation(rotation, Vector3d.ZAxis, position);

    Bref.Transform(mt)

 

    Scale3d s=new Scale3d(scale, scale, scale);

    Bref.ScaleFactors=s;

    

    // whatever extra work you need to do with this block refernece

}

 

So, you might want to explain the process from user's point of view step by step and what information about the block is known prior to inserting, and why you think you have to use jig in that case.

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 10
Anonymous
in reply to: norman.yuan

I need to be able to rotate the block visually on the fly after inserting so yes I do believe I need to use jigs. My code first brings up a menu of block types (gate valves, hydrants, etc.). The operator selects what type he wants then if that type needs an attribute a second dialog box opens, size or whatever is selected the then the code fires the sub with the jigs. The first thing that happens is the PromptResult confirms the type of block I selected, this is what I want to bypass because it already has the block name. It is an unnecessary extra step. The program should just ask for the insertion point then the rotation.
So to reiterate I know the block name but the insertion point and rotation are unknown so I can't programmatically just insert the block. User input is required for those two steps but not the first, the block name, it is already established.
Does this help?
Message 7 of 10
norman.yuan
in reply to: Anonymous

OK, now I know you do need jig to get user input for insertion point/rotation. But jig has nothing to do with block name: you can only start a jig (EntityJig, or DrawJig, does not matter here) AFTER the block reference is created (so you can "jig" it show give user visual hint), which means the block name , as a piece of required information has already been used before the jig exists.

 

Since you asking in developer" forum, I assumed you code your own jig. Are you using a jig developed by someone else that includes a step of asking block name? If you code your own Jig, for example a EntityJig, you can simply pass the block name in the constructor and use that block name to create BlockReference instance before jig dragging.

 

Unless you show your code, I have no idea why there is need to show PromptResult (meaning a user input) to confirm block name even the block name is already known.

 

So, my short answer to your question (the title of your post) is, you can insert block anyway you want (with code), using jig or not, depending on what information you already know; there is no need to confirm block name in the jig if the name is already known. If the jig is predefined/existing component, you either live with it, or you write your own.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 8 of 10
Anonymous
in reply to: norman.yuan

Thanks, now that is good information. Yes, I took a sample snipet and modified it. I'm not sure at all how to accomplish what you suggest. Below is a bit of the sub to give you an idea of how it works. Any suggestions on how to modify it would be greatly appreciated.

'INSERT BLOCK WITH JIG and attributes

Public Shared Sub InsertBlockRotateAndAddAttributesWithJigs(blkName As String, ByVal AttrValue As String)
Dim doc As Document = APPS.Core.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim pr As PromptResult = ed.GetString(blkName)
Dim position As New Point3d

Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable =
DirectCast(tr.GetObject(db.BlockTableId, dbAPPS.OpenMode.ForRead), BlockTable)
Using br As New BlockReference(Point3d.Origin, bt(blkName))
br.TransformBy(ed.CurrentUserCoordinateSystem)

Dim brRef As BlockReference = br
Dim pos As Point3d = br.Position
' Using InsertBlockJig class to insert the block
Dim insertJig As New InsertBlockJig(br)
pr = ed.Drag(insertJig)
If pr.Status <> PromptStatus.OK Then
Return
End If
' Using RotateBlockJig class to rotate the block
Dim rotateJig As New RotateBlockJig(br)
pr = ed.Drag(rotateJig)
If pr.Status <> PromptStatus.OK Then
Return
End If
rotateJig.UpdateRotation()
Message 9 of 10
norman.yuan
in reply to: Anonymous

If you look at the code carefully, the use of 2 jigs in your code (InsertBlockJig and RotateBlockJig) only happens AFTER the block reference is created (which requires block name as input) - exactly as I said previously: jig has nothing to do with the blcok name.

 

Since you have already pass the block name into the method InsertBlockRotateAndAddAttributesWithJig() method, this line (the bold red portion)

 

Dim pr AsPromptResult = ed.GetString(blkName)

 

is completely useless (the retured PromptResult is not used in following code at all). What you need here is only to declare a varaibaler "pr" as PromptResult type. So, change it to

 

Dim pr As PromptResult

 

Then you are good.

Norman Yuan

Drive CAD With Code

EESignature

Message 10 of 10
Anonymous
in reply to: norman.yuan

You da man. Thanks
Works great.

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

Post to forums  

Autodesk Design & Make Report