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

Using propertydescriptor to get all properties

7 REPLIES 7
Reply
Message 1 of 8
Viktor_Cad
540 Views, 7 Replies

Using propertydescriptor to get all properties

I am using propertydescriptor and collection to get all the properties for autocad entity. that works well, but I was wondering if there's a way to get the value and set the value of that property? I see that there's a .GetValue, but that does not return what I expected, it returns an objectID.

Anyway, is it at all possible to get and set a value of a property without doing this lineobj.Layer = blablabla, rather something like this lineobj.Property("Layer").SetValue = blablabla.

Thanks, I know the latter is not possible, my programming vocabulary is growing, would this be the difference between declarative and nondeclarative?

Viktor.
7 REPLIES 7
Message 2 of 8
Viktor_Cad
in reply to: Viktor_Cad

Ok, nevermind... You CAN use PropertyDescriptor.GetValue and .SetValue to get and set the values, but since a property can be a string of data or a Point or an ObjectID for some properties, you would just have to know what you're needing. Anyway, i'm still researching this so if someone has something to share and set me on the straight path, please do.
Message 3 of 8
Anonymous
in reply to: Viktor_Cad

Each property's type differs, so GetValue() must return a
property's value boxed in an object.

An object is like a container that can contain any type of data,
so you cast it to the actual contained type in order to use it as
that type.

Yes, you can get/set properties using PropertyDescriptor's
GetValue and SetValue methods.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6243145@discussion.autodesk.com...
I am using propertydescriptor and collection to get all the properties for
autocad entity. that works well, but I was wondering if there's a way to get
the value and set the value of that property? I see that there's a
.GetValue, but that does not return what I expected, it returns an objectID.

Anyway, is it at all possible to get and set a value of a property without
doing this lineobj.Layer = blablabla, rather something like this
lineobj.Property("Layer").SetValue = blablabla.

Thanks, I know the latter is not possible, my programming vocabulary is
growing, would this be the difference between declarative and
nondeclarative?

Viktor.
Message 4 of 8
Viktor_Cad
in reply to: Viktor_Cad

Thanks Tony. Is there a method built in to get and set values of those properties that cannot be cast to a string? Like Points, TextStyles, Dims, etc. Its a lazy question, but honestly I don't mind writing my own methods to treat these, I just dont want to be reinventing the wheel.

What I'm working on is an audit/rules application (not sure why autocad don't built it in). Right now its all spaghetti code with rules hardcoded, all in vba. Now that I'm redoing all of it to .net I am building it so the admin can put the rules in the DB and then when an audit is performed, a matrix of rules (properties with values) is built and cab be run against the drawings. Then give an option to the user to fix the issues.

That's why i'm looking to build it without hardcoding as much as possible. It'd be nice to pass the name of a style to the style property and have it accept it and all those other things. As of right now the only way I see it is if I add a method for each of the objects, so that I can pull out the values I want and set the values I want.
Message 5 of 8
Anonymous
in reply to: Viktor_Cad

For properties whose type is ObjectId, you should not be persisting them as
strings to start with (usually). By persisting them as strings, I mean that
rather than persist the ObjectId of something like a Layer, you instead
persist the value of the layer's Name property.

Why? Because in the case of things like layers, a user can rename them, and
doing that would obviously invalidate any string-based reference to them.

If you're storing data in the drawing, for data that refers to something in
the same drawing, like a Layer, you should be persisting the Layer's
ObjectId, not its name.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6243758@discussion.autodesk.com...
Thanks Tony. Is there a method built in to get and set values of those
properties that cannot be cast to a string? Like Points, TextStyles, Dims,
etc. Its a lazy question, but honestly I don't mind writing my own methods
to treat these, I just dont want to be reinventing the wheel.

What I'm working on is an audit/rules application (not sure why autocad
don't built it in). Right now its all spaghetti code with rules hardcoded,
all in vba. Now that I'm redoing all of it to .net I am building it so the
admin can put the rules in the DB and then when an audit is performed, a
matrix of rules (properties with values) is built and cab be run against the
drawings. Then give an option to the user to fix the issues.

That's why i'm looking to build it without hardcoding as much as possible.
It'd be nice to pass the name of a style to the style property and have it
accept it and all those other things. As of right now the only way I see it
is if I add a method for each of the objects, so that I can pull out the
values I want and set the values I want.
Message 6 of 8
Anonymous
in reply to: Viktor_Cad

BTW, the Entity type should have string-type properties corresponding to
most ObjectId-type properties, so in the case of simply setting/getting
values, you can use the string property instead of the ObjectId property.

For example, the Entity's Layer property returns the name of the layer,
while the LayerId property returns the layer's ObjectId.

See the attached pic. It shows some properties of an entity, and you can
see that for each property whose name ends with 'Id', there is a
corresponding property that returns the name of the object as a string. For
example, the Linetype property returns the name of the referenced Linetype,
and the Material property returns the name of the referenced material.

If you are not persisting references to things like layers and only need to
get/set values using string names, you can use the string equivalents..

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6243758@discussion.autodesk.com...
Thanks Tony. Is there a method built in to get and set values of those
properties that cannot be cast to a string? Like Points, TextStyles, Dims,
etc. Its a lazy question, but honestly I don't mind writing my own methods
to treat these, I just dont want to be reinventing the wheel.

What I'm working on is an audit/rules application (not sure why autocad
don't built it in). Right now its all spaghetti code with rules hardcoded,
all in vba. Now that I'm redoing all of it to .net I am building it so the
admin can put the rules in the DB and then when an audit is performed, a
matrix of rules (properties with values) is built and cab be run against the
drawings. Then give an option to the user to fix the issues.

That's why i'm looking to build it without hardcoding as much as possible.
It'd be nice to pass the name of a style to the style property and have it
accept it and all those other things. As of right now the only way I see it
is if I add a method for each of the objects, so that I can pull out the
values I want and set the values I want.
Message 7 of 8
Viktor_Cad
in reply to: Viktor_Cad

Thanks Tony. Yea, Inotice that most properties do have a corresponding string-type property, although there are some like points that do not, which is not that bad.

One other question is in regard to performance when accessing properties through a property descriptor, is that not very efficient? So far with only a couple of rules in my database (which equals to a couple of properties checked per specific entity) things are moving pretty quick, but I'm wondering if I will see a hit once I have 30-50 or even more rules. Or is this just as efficient as accessing properties directly?

Thanks,
Viktor.
Message 8 of 8
Anonymous
in reply to: Viktor_Cad

Getting properties through reflection is generally slower than directly
accessing them, because of the boxing/unboxing to/from System.Object, but
unless you are accessing many thousands of properties, there should be
little perceivable difference from the user's perspective.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6244635@discussion.autodesk.com...
Thanks Tony. Yea, Inotice that most properties do have a corresponding
string-type property, although there are some like points that do not, which
is not that bad.

One other question is in regard to performance when accessing properties
through a property descriptor, is that not very efficient? So far with only
a couple of rules in my database (which equals to a couple of properties
checked per specific entity) things are moving pretty quick, but I'm
wondering if I will see a hit once I have 30-50 or even more rules. Or is
this just as efficient as accessing properties directly?

Thanks,
Viktor.

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