PDA

View Full Version : Create Dynamic Block



bweir
2008-02-05, 08:10 PM
I'm trying to write a function that will create a dynamic block definition for me. I can create the block and geometry no problem. I have no idea where to start for adding dynamic properties (parameters and actions) to the block definition. Any suggestions?

artisteroi
2008-02-05, 08:48 PM
I'm trying to write a function that will create a dynamic block definition for me. I can create the block and geometry no problem. I have no idea where to start for adding dynamic properties (parameters and actions) to the block definition. Any suggestions?

last I heard the block editor deactivates all scripting while it is enabled. So you can't actually make the dynamic properties using a secondary software. You have to do it manually. Sorry

bweir
2008-02-05, 09:08 PM
Maybe I should clarify. I'm not using scripts or the block editor. I'm trying to develop a function using the VB.NET API.

artisteroi
2008-02-05, 09:25 PM
Maybe I should clarify. I'm not using scripts or the block editor. I'm trying to develop a function using the VB.NET API.


my bad. By script I mean any type of automatic programming, script, lisp, vb, even dot.net. It's all scripting of one sort or another. So the block editor shuts it off. becuase the block editor is a script program as well, it just uses a gui instead of code processing. I don't think it can be done.

bweir
2008-02-05, 09:48 PM
Sorry, again I'm NOT using the block editor. I define a BlockTableRecord and add it to the BlockTable of the database. Something like this...


Dim Blocks As BlockTable
Dim ObjId As ObjectId
Dim Block As BlockTableRecord
Dim Trans As Transaction
Dim BasePoint As Point2d

Trans = Database.TransactionManager.StartTransaction
Try
Blocks = Trans.GetObject(Database.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, False, False)
ObjId = Blocks.Add(New BlockTableRecord)

Block = Trans.GetObject(ObjId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite, False, False)
Block.Name = "MyBlockNameHere"
Block.Units = Autodesk.AutoCAD.DatabaseServices.UnitsValue.Undefined
Block.BlockScaling = Autodesk.AutoCAD.DatabaseServices.BlockScaling.Uniform
Block.Comments = "This block is generated automatically and should not be edited."
Block.Explodable = False

Trans.AddNewlyCreatedDBObject(Block, True)

' Code to add geometry goes here...

' Need some other code here to add dynamic properties???

Catch ex As Autodesk.AutoCAD.Runtime.Exception
Application.ShowAlertDialog("CreateBlock" & vbNewLine & ex.ToString)
Block = Nothing
Trans.Abort()
Finally
Trans.Dispose()
Trans = Nothing
Database = Nothing
End Try

artisteroi
2008-02-06, 01:44 PM
Right Right.
What I mean is that you can't add parameters and actions to a block without accessing the block editor. Those items don't exist in standard model space. you must access the block editor to create a dynamic block.
the 'bedit' & name of block reference commands will open the editor but as soon as it is open the .net protocals will be deactivated. The code will just stop or truncate. Probably crash autocad. Or it will say you can't call the block editor while a command is active, the command being the .net script.
if you try to add a parameter or action to a block outside the block editor you will get a error message that says "that command is only allowed inside the block editor". Think of the block editor as a sort of sub-model space. what is possible in the block editor like actions and parameters are imposible in model space. and what is possible in model space like macros and scripting is impossible in block editor space.
It would be the same as using vba to write lisp code. you can't use one code to write another. It would cause a rift in the space-time continuum.
I could be wrong so if you can make it work please let us know. But I think you are fighting an impossible battle.

bweir
2008-02-06, 03:54 PM
Is this not exposed in the .NET API somewhere? And. Yes you can run scripts and Lisp and .NET commands from inside the Block Editor. I just tried it and everything worked fine, unless the command is marked not to run in the Block Editor which you can do with the <CommandMethod(...)> attribute in .NET.

A dynamic block is stored in the BlockTable like any other block (unless I missed something). This being the case, how do you add dynamic properties to a BlockTableRecord to make it a dynamic block? Does it have something to do with the DynamicDimensionDataCollection and how would this apply to the BlockTableRecord.

bweir
2008-02-06, 04:59 PM
I've been inspecting some dynamic blocks I've created. It looks like the dynamic property information might be stored in the blocks ExtensionDictionary. Can anybody help confirm this for me?

artisteroi
2008-02-06, 06:16 PM
Is this not exposed in the .NET API somewhere? And. Yes you can run scripts and Lisp and .NET commands from inside the Block Editor. I just tried it and everything worked fine, unless the command is marked not to run in the Block Editor which you can do with the <CommandMethod(...)> attribute in .NET.

A dynamic block is stored in the BlockTable like any other block (unless I missed something). This being the case, how do you add dynamic properties to a BlockTableRecord to make it a dynamic block? Does it have something to do with the DynamicDimensionDataCollection and how would this apply to the BlockTableRecord.

great you got scripting to work inside the block editor. I guess autodesk was wrong again, they were the ones who said the editor would shut off scripting. Kewl

the dynamic blocks are stored in the btr just like other blocks. when you run the code check block for "isdynamic = true" and then "blockref.getdynamicproperties" will allow you to change them. But I don't know how you would create them since I never tried to run a script inside the block editor since I was told it was impossible.

bweir
2008-02-06, 07:08 PM
great you got scripting to work inside the block editor. I guess autodesk was wrong again, they were the ones who said the editor would shut off scripting. Kewl
I think what you are referring to regarding scripting is if you run a script and that script executes the BEDIT command, the script will stop until the BEDIT command has finished (that is the Block Editor has closed).



the dynamic blocks are stored in the btr just like other blocks. when you run the code check block for "isdynamic = true" and then "blockref.getdynamicproperties" will allow you to change them. But I don't know how you would create them since I never tried to run a script inside the block editor since I was told it was impossible.
AND Again I'm not using the Block Editor to create the block, I'm using a program I've written my self to create and edit the block. I need to know what data I need to add to the block definition to make it a dynamic block. I've found that dynamic blocks have a entry in the ExtendedDictionary of the block named ACAD_ENHANCEDBLOCK. I'm assuming this is the data that defines the dynamics but I don't know what to put in it.

artisteroi
2008-02-06, 08:04 PM
I guess you are getting ahead of me. This is how I would do it.
write code to draw block in model space
define drawn object as block/ block ref
open block editor (this is where it would stop)
create dyna props
close block editor
update block ref

artisteroi
2008-02-06, 08:11 PM
I suppose if you can get the programming to operate with the block editor active then it would just be a matter initiating the .net dll while the block editor is active and telling it which parameters and actions to call. but that is a fairly visual process, not sure you would be saving anything by automating it. but it would be a cool experiment if you can get it to function. maybe try something simple first like a visibility or a flip parameter

bweir
2008-02-07, 03:32 PM
artisteroi,
I'm not sure how you do your programming. It sounds like you're telling me to use command calls?

artisteroi
2008-02-07, 04:47 PM
artisteroi,
I'm not sure how you do your programming. It sounds like you're telling me to use command calls?

yes command calls. but I guess that shows how old school I am. I learned programming for VBA and Lisp. dot net is a whole new animal, which quite frankly, I havn't had much success with, it is very alien. So I will just let you work out the details for yourself. you are more advanced than I am.

bweir
2008-02-07, 07:23 PM
AAAAAAHHHHHH:shock:, I hate command calls they should never ever be used. I loathe programmers who are lazy enough to use this method of programming. That's not programming, there's no error trapping, no returned values to work with, you just guess and hope things want ok. That's c^@#!:p

dgorsman
2008-02-07, 08:55 PM
To be fair, they have their place with LISP, and sometimes in VBA, but certainly not in .NET.

Is there anything in the program object model about dynamic block object properties? I suspect, like you do, there is some XDATA involved; you may have to investigate "inside" some inserted blocks (dynamic and not) to compare the data.

artisteroi
2008-02-07, 08:58 PM
the difference being is that I actually learned to design before learning to code. so many coders think that because they can make cad draw a line in a certain place that makes them a designer. That is what is real ****. and there are a ton of cad add ons that will take a perfectly good drawing automate some minor item and make the whole thing look like dren. But I guese if you knew how to draw using the commands, then you wouldn't need to program using a "method".
Like I said, I am old school.:beer:

T.Willey
2008-02-08, 12:29 AM
Have you downloaded the ObjectARX SDK for you Acad version? If so, did you look in the samples folder? If so, did you see the dotNet folder? If so, did you see the DynamicBlock folder? If so, did you look and see the three vb code files theres to show you have to mess with dynamic blocks?


DynamicBlock .NET API Sample Readme.txt

(C) Copyright 2004 by Autodesk, Inc.

This sample demonstrates listing and manipulating the property values of a dynamic block
reference.

There are three commands:

DynList - Lists at the command line all the properties of dynamic block references in the drawing.

DynEdit - Displays the properties of a dynamic block in a DataGrid. The grid shows four columns.

1. Name - Name of the parameter or property (ReadOnly)
2. Type - The data type for the property value. See the Enum PropTypeCode for a list of types (ReadOnly)
3. Value - The value of the parameter. Editable. Any
erroneous input will notify the user.
4. Description - The description of the property (ReadOnly)

Once done editing, press the OK button to dismiss the form. The changes made to the
properties can now be seen in the drawing.

DynFreeze - Converts a dynamic block reference to a regular (or static) block reference

Demo:

Load DynamicBlock.dll from the \bin folder into AutoCAD using NETLOAD command.
Play with the above commands. Rereferencing acmgd.dll and acdbmgd.dll may be necessary to build the project.

bweir
2008-02-08, 03:39 PM
Thanks T.Willey but I have looked at this project already. I didn't notice anything in the project to create a dynamic block definition but I'll have another look in case I missed something.

T.Willey
2008-02-08, 04:14 PM
Thanks T.Willey but I have looked at this project already. I didn't notice anything in the project to create a dynamic block definition but I'll have another look in case I missed something.

I didn't see anything to create either, but I thought you might get an idea of how to do it from these. I don't use dy blocks, so I'm not much help besides what I posted. Hope you find something.

bweir
2008-02-13, 06:53 PM
Still haven't found anything on how to create a dynamic block or modify a dynamic block definition using AutoCAD's .NET API. Think this is an item for the wish list.

T.Willey
2008-02-13, 07:48 PM
Looks like all the properties are kept in the extension dictionary of the block table record. At least that is how I got there with lisp.

But I don't see what to do from there with .Net.

bweir
2008-02-13, 11:12 PM
Looks like all the properties are kept in the extension dictionary of the block table record. At least that is how I got there with lisp.

But I don't see what to do from there with .Net.

I think I've gotten to about the same point with .NET. There is some sort of object called an "ImpDBObject" in the dictionary. I'm guessing it holds the secret to the Dynamic Block Definition. I don't know where this object comes from or if I can include it in my .NET project. Any ideas?

T.Willey
2008-02-14, 04:37 PM
If I wanted to know how to build stuff with the .Net language, I would go here (http://autodesk.blogs.com/between_the_lines/2006/07/dbview_for_auto.html)and download the db view arx. It will show you the items that make up a dynamic block, and then it might help you along your path with other questions.

Attached is a sample look at one of my dynamic blocks (the only one I have done so far). You can see the items that are in the extension dictionary, and the names of such items, and hopefully that will start you on your path.

When you do find how to do this, I hope you will share your code so others can learn from what you have done.

bweir
2008-02-14, 07:18 PM
Thanks, I'll give it a try.

T.Willey
2008-02-27, 10:09 PM
Don't want to tell you you can't define dynamic blocks in code, because you can do that even in LISP, using nothing but (entmake).

But doing that will require you to reverse-engineer all of the "authoriing components" like parameters and actions. There are no APIs or managed wrappers for those objects so there's nothing the NET API can do to make it any easier.

Thanks for the heads up Tony.

Keith.Massey.158205
2012-09-06, 01:52 PM
Follow this thread as i wish to start BEditor and enter <Current Drawing> from a script see below
where i want to replace xx with -BE <Current Drawing>, but from what you say i can not enter BE from script, however this script start out of BE then can be resumed in BE

Any guidance

Open C:/Library/Rap2/R008D01
xx
-BVState S Front
-Insert C:/Library/Rapid/Rap1/R008D02
0,0 1 1 0 -BVState N
End To
H -Insert C:/Library/Rapid/Rap1/R008D03
0,0 1 1 0 -BVState N
End Away
H -Insert C:/Library/Rapid/Rap1/R008D04
0,0 1 1 0 -BVState N
Plan To
H -Insert C:/Library/Rapid/Rap1/R008D05
0,0 1 1 0 -BVState N
45° To
H -Insert C:/Library/Rapid/Rap1/R008D07
0,0 1 1 0 -BVState N
45° Away
H -Insert C:/Library/Rapid/Rap1/R008D08
0,0 1 1 0 -BVState S Front
BVMode 1 DiddlePoints BVMode 0 _Bsave Bclose Zoom E Qsave Close