Best object for automatic creation: Xrecord or Xdata

Best object for automatic creation: Xrecord or Xdata

Anonymous
Not applicable
1,498 Views
20 Replies
Message 1 of 21

Best object for automatic creation: Xrecord or Xdata

Anonymous
Not applicable
I've been trying to find a solution to a problem. We have with moving a lot of our drawings into AutoCAD from another program, and the biggest concern we have is unique identifiers. Basically, we have blocks that each represent a specific object in the drawing that, later, need to be unique for a particular building and ALWAYS be unique. We have an automated program that, once I find a solution for, should take these objects and save their data off into a database somewhere else to track these objects, their properties, ect.

Currently, I'm looking at the handles of these objects and exporting the handles as the unique identifier. However, extra data might need to be added to these at the creating of the objects. Example: someone goes into the drawing and needs to add a new object. The desired effect would be that they draw the object or block out and save it. Once done being drawn, they attach some type of added object to it that would allow them to input data for that object. Either that, or have the data inputed before the can actually draw it.

I need help determining what the best way to store uniquie object data is.

Thanks in advance.
0 Likes
1,499 Views
20 Replies
Replies (20)
Message 2 of 21

arcticad
Advisor
Advisor
Each object will have a unique handle that is only applicable to the current drawing., as soon as it is exported or imported into another drawing the handle will change.

You would need to store this information in some kind of database to track them across drawing,

You also going to have to deal with an object that is new or copied. You may want to run some initialization routine on new objects.

As far as I know, the events won't distinguish between a new item and copied item.

Having a record of initialization stored in the object may be of benefit.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 21

Anonymous
Not applicable
-object id is the same for each object, but (i think) objects are
renumerated every time autocad opens drawing
-object handle is the same always for each single unit object, and every
time as long they are in the same drawing

not fully understand your project or problems, but i'm about to deal with
this myself soon, and this is how i planed it:
-user creates object, my program does his things and saves result in objects
xrecord, and first xrecord data value will be objects graphic handle
-also, i add to object xdata application name for later getting selection
set

-every object in drawing is my and ok only if handle in xrecord is same as
actual handle (if not, it is pasted object)
-if it pass this test, then i read rest of xrecord and use my data
-if i want to import new objects, then in check this in original drawing,
copy them in new and write new xrecord handle

potential problem with this - what if i only have 2 objects in file
first drawing: 2 objects, first has handle A, second handle B
paste in new drawing second object, but autocad gives it handle A?
is this scenario possible?

also, if part of your question was xrecord od xdata?
well, as i see it, xdata is usefull for xdata filtering selection only
xrecord, dictionary can hold more data

-keep in mind - i'm still an amater, just few month in this
0 Likes
Message 4 of 21

Anonymous
Not applicable
Hi,

In my knowledge, handles are unique inside a dwg, each object will have a
different handle inside a single dwg database, and also handles are
persistent, meaning that the handle will be saved with the dwg. By other
side, objectIds are unique to a session, meaning that in a single session
will not be 2 objects with the same objectId, no matter the dwg database,
but they are not persistent.

Finally if you need to store data in an external database, the pair
handle,dwgfileName will be a key.

-gnb

"ljb" wrote in message
news:6370820@discussion.autodesk.com...
> -object id is the same for each object, but (i think) objects are
> renumerated every time autocad opens drawing
> -object handle is the same always for each single unit object, and every
> time as long they are in the same drawing
>
> not fully understand your project or problems, but i'm about to deal with
> this myself soon, and this is how i planed it:
> -user creates object, my program does his things and saves result in
> objects xrecord, and first xrecord data value will be objects graphic
> handle
> -also, i add to object xdata application name for later getting selection
> set
>
> -every object in drawing is my and ok only if handle in xrecord is same as
> actual handle (if not, it is pasted object)
> -if it pass this test, then i read rest of xrecord and use my data
> -if i want to import new objects, then in check this in original drawing,
> copy them in new and write new xrecord handle
>
> potential problem with this - what if i only have 2 objects in file
> first drawing: 2 objects, first has handle A, second handle B
> paste in new drawing second object, but autocad gives it handle A?
> is this scenario possible?
>
> also, if part of your question was xrecord od xdata?
> well, as i see it, xdata is usefull for xdata filtering selection only
> xrecord, dictionary can hold more data
>
> -keep in mind - i'm still an amater, just few month in this
0 Likes
Message 5 of 21

Anonymous
Not applicable
so, you say - if i have 5 opened documents with 2 objects per doc, i have 5
x 2 = 10 unique objectids in autocad at once?
but also, can it happen that i also have 5 x 2 <> 10 unique handles?

"Gaston Nunez" wrote in message
news:6370886@discussion.autodesk.com...
Hi,

In my knowledge, handles are unique inside a dwg, each object will have a
different handle inside a single dwg database, and also handles are
persistent, meaning that the handle will be saved with the dwg. By other
side, objectIds are unique to a session, meaning that in a single session
will not be 2 objects with the same objectId, no matter the dwg database,
but they are not persistent.

Finally if you need to store data in an external database, the pair
handle,dwgfileName will be a key.
0 Likes
Message 6 of 21

Anonymous
Not applicable
Both cases are different:

First case: objectIds, are always unique in a session, no matter how many
dwg databases are opened in the same session. The objectIds are not
persistent, meaning that the next time (new session) the same dataset (dwg
files) be opened, the objectIds will be different for the same entities.

Second case: handles, may be or may be not unique across multiple dwg
databases opened in a single session, what it's granted is that handles are
unique inside a single dwg database. So it's perfectly possible to have 2
objects from distinct dwg databases with the same handle. Handles are saved
to the dwg file.

I'm not sure what are you trying to do, but if you need to store and
identify AutoCAD entities in a database, a combination of handle and
dwgFileName conform a unique key for an entity.


-gnb






"ljb" wrote in message
news:6370926@discussion.autodesk.com...
> so, you say - if i have 5 opened documents with 2 objects per doc, i have
> 5 x 2 = 10 unique objectids in autocad at once?
> but also, can it happen that i also have 5 x 2 <> 10 unique handles?
>
> "Gaston Nunez" wrote in message
> news:6370886@discussion.autodesk.com...
> Hi,
>
> In my knowledge, handles are unique inside a dwg, each object will have a
> different handle inside a single dwg database, and also handles are
> persistent, meaning that the handle will be saved with the dwg. By other
> side, objectIds are unique to a session, meaning that in a single session
> will not be 2 objects with the same objectId, no matter the dwg database,
> but they are not persistent.
>
> Finally if you need to store data in an external database, the pair
> handle,dwgfileName will be a key.
0 Likes
Message 7 of 21

Anonymous
Not applicable
Well, this does confirm what I've been thinking for a while about this problem. Things will have to be a composite key between DWG and handle. Storing the handle into Xrecord of objects would be the next good idea?

The idea here, or the project I'm working on, is still in it's beginning phase, so this is just trying to flesh out ideas and solutions for those ideas. I think it should be possible to do this with handles. One question I have from this is: is there another way to key the drawing rather then the drawing name? Does the dwg itself have a key or handle, or am I relying on the name. My first reaction would be, only name.
0 Likes
Message 8 of 21

Anonymous
Not applicable
What many do is use a data table that stores both
the DWG filename keyed to a unique identifier that
can be nothing more than a integer.

That table can be used to lookup the filename so
it doesn't have to be stored with each handle.


--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

wrote in message news:6371079@discussion.autodesk.com...
Well, this does confirm what I've been thinking for a while about this problem.
Things will have to be a composite key between DWG and handle. Storing the
handle into Xrecord of objects would be the next good idea?

The idea here, or the project I'm working on, is still in it's beginning phase,
so this is just trying to flesh out ideas and solutions for those ideas. I
think it should be possible to do this with handles. One question I have from
this is: is there another way to key the drawing rather then the drawing name?
Does the dwg itself have a key or handle, or am I relying on the name. My first
reaction would be, only name.
0 Likes
Message 9 of 21

Anonymous
Not applicable
as i see it, the file name has tendency to become useless
for example - what if user has multiple open documents and some of them are
the same (he opens same file but as read only)
and also for storing name - what if user renames files?

there must be some hash or something to get by this thing
maybe you wanted to say - to write in file NOD some unique number and also
same one in xrecord of entitys?

for - i think that the problem of copy/pasted object within a file is solved
by using handle written in xrecords
(if we didn't write its handle in xrecord, than it is not ours)
what is left is when user copy/paste objects from file to file, and autocad
(low chance but possible) gives some of that object same handle like one he
had in file before in wich case - xrecord and handle are correct, but entity
is still not ours in this new file

so is than number to write in file nod, and entity xrec to be RND(double)?
or is there some hash that file internaly has (like objects have handle)?



"Tony Tanzillo" wrote in message
news:6371311@discussion.autodesk.com...
What many do is use a data table that stores both
the DWG filename keyed to a unique identifier that
can be nothing more than a integer.

That table can be used to lookup the filename so
it doesn't have to be stored with each handle.
0 Likes
Message 10 of 21

Anonymous
Not applicable
No, by 'filename' I mean the full path to the file, not just
the file's name.

If the file is moved, then the database would have to be
updated.

--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

"ljb" wrote in message news:6375069@discussion.autodesk.com...
as i see it, the file name has tendency to become useless
for example - what if user has multiple open documents and some of them are
the same (he opens same file but as read only)
and also for storing name - what if user renames files?

there must be some hash or something to get by this thing
maybe you wanted to say - to write in file NOD some unique number and also
same one in xrecord of entitys?

for - i think that the problem of copy/pasted object within a file is solved
by using handle written in xrecords
(if we didn't write its handle in xrecord, than it is not ours)
what is left is when user copy/paste objects from file to file, and autocad
(low chance but possible) gives some of that object same handle like one he
had in file before in wich case - xrecord and handle are correct, but entity
is still not ours in this new file

so is than number to write in file nod, and entity xrec to be RND(double)?
or is there some hash that file internaly has (like objects have handle)?



"Tony Tanzillo" wrote in message
news:6371311@discussion.autodesk.com...
What many do is use a data table that stores both
the DWG filename keyed to a unique identifier that
can be nothing more than a integer.

That table can be used to lookup the filename so
it doesn't have to be stored with each handle.
0 Likes
Message 11 of 21

Anonymous
Not applicable
Well, I've gotten as far as creating a demo or sample of how I'm going to create these Xrecords, but now I'm very, very confused. I've never really dealt with typed values or dictionaries in AutoCAD or anything like this. So this whole process of adding data to objects just seems confusing.

What I want to do for my demo is simply add an XRecord to an object when it's being created or has been created. I can program this up to the XRecord part. That's when it gets confusing. Shouldn't it just be as simple as telling the XRecord what keys I want for the XRecord I'm adding, then setting those values and adding that XRecord to the object? What I'm seeing is a bunch of result buffers and typed values. And I don't know what any of that really means.
0 Likes
Message 12 of 21

Anonymous
Not applicable
Have you done much AutoCAD.NET development before?

--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

wrote in message news:6375596@discussion.autodesk.com...
Well, I've gotten as far as creating a demo or sample of how I'm going to create
these Xrecords, but now I'm very, very confused. I've never really dealt with
typed values or dictionaries in AutoCAD or anything like this. So this whole
process of adding data to objects just seems confusing.

What I want to do for my demo is simply add an XRecord to an object when it's
being created or has been created. I can program this up to the XRecord part.
That's when it gets confusing. Shouldn't it just be as simple as telling the
XRecord what keys I want for the XRecord I'm adding, then setting those values
and adding that XRecord to the object? What I'm seeing is a bunch of result
buffers and typed values. And I don't know what any of that really means.
0 Likes
Message 13 of 21

Anonymous
Not applicable
I haven't done that much. I've created a few progams that could iterate through objects on the model space and also change text elements based on spreadsheets entered in. This would be the first real thing I've developed.
0 Likes
Message 14 of 21

Anonymous
Not applicable
You should probably consider using whatever materials are
available to help become more familiar with the managed
ObjectARX API. Searching this newsgroup usually turns
up some useful subjects, and the online documentation has
some helpful sample code, although I don't know if it covers
storing custom/user data in objects.

Xrecords are not attached directly to entities, they are
stored in an entity's Extension Dictionary.

--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

wrote in message news:6376229@discussion.autodesk.com...
I haven't done that much. I've created a few progams that could iterate through
objects on the model space and also change text elements based on spreadsheets
entered in. This would be the first real thing I've developed.
0 Likes
Message 15 of 21

Anonymous
Not applicable
Thanks for the help so far. I have been working with much of the documentation and working with entities. XRecords and XData, as well as other custom object data, has been something that there is little to nothing on the internet that I can find. I can find examples, but this doesn't tell me what these things inherently are. What you've told me makes me a little concerned.

So XRecords are not linked to an object, but they're stored in their extension dictionary? Does this mean I won't be able to use it to uniquely identify these stations in them?
0 Likes
Message 16 of 21

dgorsman
Consultant
Consultant
Ironically, I would suggest checking the VBA documentation - it has an object map which shows the basic relationships between objects and collections such as dictionaries and xrecords.
----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 17 of 21

Anonymous
Not applicable
{quote}

So XRecords are not linked to an object, but they're stored in their extension
dictionary? Does this mean I won't be able to use it to uniquely identify these
stations in them?

{quote}

No, XRecords are linked to objects, just not directly.

Every object can have an extension dictionary, and
that extension dictionary holds all 'linked' objects,
including xrecords, and other 'child' dictionaries.

You can consult the native ObjectARX documenation
for detailed explainations about what xrecords and
extension dictionaries are.

--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

wrote in message news:6376386@discussion.autodesk.com...
Thanks for the help so far. I have been working with much of the documentation
and working with entities. XRecords and XData, as well as other custom object
data, has been something that there is little to nothing on the internet that I
can find. I can find examples, but this doesn't tell me what these things
inherently are. What you've told me makes me a little concerned.

So XRecords are not linked to an object, but they're stored in their extension
dictionary? Does this mean I won't be able to use it to uniquely identify these
stations in them?
0 Likes
Message 18 of 21

Anonymous
Not applicable
i'm still a beginner in this and only a part time programmer, so i really
appreciate your WILL to anwser Tony
but i still think you might be wrong and file name in this context is
useless!

for example - try to look at document manager opened files, and open same
file several times. i may be doing something wrong but all i can rely is
(document).gethascode, not filename itself

and, all being said - the only thing that is left - is to hope that autocad
will not (by chance) give same handle to copied object (being pasted without
ours app running in that session, since if it is in our session then one can
track it by objectid)

"Tony Tanzillo" wrote in message
news:6375103@discussion.autodesk.com...
No, by 'filename' I mean the full path to the file, not just
the file's name.

If the file is moved, then the database would have to be
updated.
0 Likes
Message 19 of 21

Anonymous
Not applicable
You might not understand what the OP wants to do.

The OP needs to uniquely identify objects across
multiple files within a single namespace, outside of
the AutoCAD environement (e.g., a database, an
excel worksheet, etc.).

That means that both the file and the handle of the
object must be used to uniquely reference the object.

What really puzzles me, is that if you have an external
database that contains references to objects in more
than one DWG file, how else could you possibly open
the file containing one of those objects and access it,
without the filename?



--
http://www.caddzone.com

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

http://www.acadxtabs.com

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

"ljb" wrote in message news:6379997@discussion.autodesk.com...
i'm still a beginner in this and only a part time programmer, so i really
appreciate your WILL to anwser Tony
but i still think you might be wrong and file name in this context is
useless!

for example - try to look at document manager opened files, and open same
file several times. i may be doing something wrong but all i can rely is
(document).gethascode, not filename itself

and, all being said - the only thing that is left - is to hope that autocad
will not (by chance) give same handle to copied object (being pasted without
ours app running in that session, since if it is in our session then one can
track it by objectid)

"Tony Tanzillo" wrote in message
news:6375103@discussion.autodesk.com...
No, by 'filename' I mean the full path to the file, not just
the file's name.

If the file is moved, then the database would have to be
updated.
0 Likes
Message 20 of 21

Anonymous
Not applicable
opening is not a problem, you need file name for opening, true, but checking
is that object in it is "the one" and in situation that we have left it in
(remember, if not pass protected and monitored by our app, anyone can open
dwg and mess with it)
...and so, open same file twice, use dictionary(of filename-string, data
connected to objects)
and try by using handlers - to see when your file is active. but, do not use
doc type, use doc.file name to find
you will see (al least it happened then to me) that file name returned is
the same for both files
only hashcode was different and that was how i knew to distinct files
hence, i concluded that file name is no good. and second, most important
thing - if you have noticed, some people like to have specific name for some
file, and they keep renaming files a lot and in that way, saving file name
in database is no good for tracking specific objects.

well, as i said, my solution is here:
1) to write handle in xrecord
2) to RND number and place it in NOD and then use that number and write it
in xrecord for every single my object

in that way - object when pasted to different file will have wrong that
(RND) number
and when pasted within same file - will have wrong handle

i have never write in NOD anything yet thoug, but, i think it's
strait-forward
so, for me it is solved, and i very much thank you for your time Tony!


"Tony Tanzillo" wrote in message
news:6380015@discussion.autodesk.com...
...
What really puzzles me, is that if you have an external
database that contains references to objects in more
than one DWG file, how else could you possibly open
the file containing one of those objects and access it,
without the filename?
0 Likes