马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
问题:
How to change the registered application ID ?
解答:
In AutoCAD you can attach extended entity data to an entity. The limit on this
data is 16kb per entity. The kinds of data that can be attached are string data
and numeric data. The data is associated with a registered application ID. To
register an application you use the AutoLISP regapp function. The regapp
function take a string data type up to 31 characters. Unfortunately there is no
easy function that will delete/rename the registered application ID. If there
are a number of entities in the AutoCAD drawing that have extended entity data
already attached and you want to retrieve those entities using AutoLISP, you
would use the following AutoLISP syntax:
(setq ssxd (ssget "x" '((-3 ("YOUR_APP_ID"))))
If there are entities in the drawing that have extended data and match the
application string ID, the length of the selection will be greater than zero.
Use the sslength function to find the number of entities in a selection set.
Here you would typically use a repeat loop to process each entity in the
selection set and change the registered application ID for each of the entities.
In discussing the mechanism of changing (or deleting) the registered application
name, execute the AutoLISP statements at the AuotCAD command prompt. First, draw
a single line entity in AutoCAD. Because this entity is a new entity it will not
have extended entity data attached to it.
Execute the following AutoLISP statement at the command prompt.
(setq ename (entlast))
Now the variable 'ename' contains the memory location of the entity. Register an
application ID using the regapp function as follows:
(regapp "APPID1")
Get the entity data of the 'ename' entity using
(setq edata (entget ename))
The AutoCAD command line prompt will return a list as follows:
((-1 . <Entity name: 2cf0500>) (0 . "LINE") (5 . "20") (100 ."AcDbEntity") (67.
0) (8 . "0") (100 . "AcDbLine") (10 132.586 104.055 0.0) (11 428.152200.266 0.0)
(210 0.0 0.0 1.0))
Note that there in no extended entity data in this entity as yet. Lets add some
extended entity data as follows:
(setq xd (list -3 (list "APPID1" (cons 1000 "String 1") (cons 1000 "String
2"))))
Append this list to the 'edata' list that we previously obtained as follows:
(setq edata (append edata (list xd)))
This just modifies the list and not the entity as yet.
Now we need one more call to modify the entity as follows:
(entmod edata)
AutoCAD will return the following:
((-1 . <Entity name: 2800500>) (0 . "LINE") (5 . "20") (100 . "AcDbEntity") (67
. 0) (8 . "0") (100 . "AcDbLine") (10 109.527 85.2306 0.0) (11 482.653 226.41
0.0) (210 0.0 0.0 1.0) (-3 ("APPID1" (1000 . "String 1") (1000 . "String 2"))))
You can have more than one registered application on an entity, in our case we
just have one. Now turn your attention to renaming the name of the registered
application ID while preserving the data that is associated with application ID
"APPID1". Extract the extended entity data from the entity using the registered
application ID "APPID1" as follows:
(setq edata (entget ename '("APPID1")))
AutoCAD will return data with the "APPID1" extended entity data as follows:
((-1 . <Entity name: 2800500>) (0 . "LINE") (5 . "20") (100 . "AcDbEntity") (67
. 0) (8 . "0") (100 . "AcDbLine") (10 109.527 85.2306 0.0) (11 482.653 226.41
0.0) (210 0.0 0.0 1.0) (-3 ("APPID1" (1000 . "String 1") (1000 . "String 2"))))
Pull out the extended entity data associated with the entity and save it in the
variable 'xd' as follows:
(setq xd (assoc -3 edata))
in which case AutoCAD will return the following at the command prompt.
(-3 ("APPID1" (1000 . "String 1") (1000 . "String 2")))
Extract the data that is associated with the application ID "APPID1" and store
that information inside a list of lists as follows in the variable 'keepdata':
(setq keepdata (cdr (nth 1 xd)))
AutoCAD returns the value of variable 'keepdata' as follows:
((1000 . "String 1") (1000 . "String 2"))
The variable 'keepdata' is a list of lists and contains the data that is
associated with the application ID "APPID1", which you are going to rename to
"NEWAPPNAME". In order to rename the extended entity data application ID to
"NEWAPPNAME", you actually have to delete the "APPID1" application ID. You have
saved the data that was associated with "APPID1" in the variable 'keepdata'. To
delete the "APPID1" registered application, add the application ID to the
'edata' list with no data as the following will show:
(setq xd (list -3 (list "APPID1")))
This will return at the AutoCAD command line:
(-3 ("APPID1"))
The application name has only been included without any data associated with it.
Now refresh the 'edata' variable again with the following call:
(setq edata (entget ename))
Now append the new 'xd' list to the refreshed 'edata' list with the following
call.
(setq edata (append edata (list xd)))
AutoCAD returns:
((-1 . <Entity name: 2800500>) (0 . "LINE") (5 . "20") (100 . "AcDbEntity") (67
. 0) (8 . "0") (100 . "AcDbLine")
(10 194.948 70.9925 0.0) (11 561.785 245.908 0.0) (210 0.0 0.0 1.0) (-3
("APPID1")))
Now modify the entity:
(entmod edata)
This will remove the registered app ID of "APPID1" from the entity as shown in
the following call to the refreshed 'edata' variable.
(setq edata (entget ename '("*")))
The AutoCAD command prompt returns:
((-1 . <Entity name: 2800500>) (0 . "LINE") (5 . "20") (100 . "AcDbEntity") (67
. 0) (8 . "0") (100 . "AcDbLine") (10 109.527 85.2306 0.0) (11 482.653 226.41
0.0) (210 0.0 0.0 1.0))
As you can see the registered app "APPID1" is now gone. Lets register a new app
ID called "NEWAPPNAME" as follows:
(regapp "NEWAPPNAME")
Refresh the variable 'edata' as follows:
(setq edata (entget ename))
To build up a new extended entity data list proceed as follows:
(setq xd (list -3))
(setq newxd (list "NEWAPPNAME"))
(foreach item keepdata
(setq newxd (append newxd (list item)))
);foreach
The variable 'newxd' will now look like the following:
("NEWAPPNAME" (1000 . "String 1") (1000 . "String 2"))
Append 'newxd' to 'xd' as follows:
(setq xd (append xd (list newxd)))
which returns:
(-3 ("NEWAPPNAME" (1000 . "String 1") (1000 . "String 2")))
We now need to append the 'xd' list to the refreshed 'edata' list that we
obtained earlier as follows:
(setq xd (append edata (list xd)))
which AutoCAD returns at the command prompt:
((-1 . <Entity name: 2800500>) (0 . "LINE") (5 . "20") (100 . "AcDbEntity") (67
. 0) (8 . "0") (100 . "AcDbLine") (10 109.527 85.2306 0.0) (11 482.653 226.41
0.0) (210 0.0 0.0 1.0) (-3 ("NEWAPPNAME" (1000 . "String 1") (1000 . "String
2"))))
Finally call the entmod function to add the new extended entity data to the
entity.
(entmod edata)
It is now complete. This is the manual mechanism which shows how to rename the
registered app ID. Now execute the following AutoLISP statement:
(setq edata (entget ename '("*")))
which returns the newly named registered application name with the old data
intact as shown below:
((-1 . <Entity name: 2800500>) (0 . "LINE") (5 . "20") (100 . "AcDbEntity") (67
. 0) (8 . "0") (100 . "AcDbLine") (10 109.527 85.2306 0.0) (11 482.653 226.41
0.0) (210 0.0 0.0 1.0) (-3 ("NEWAPPNAME" (1000 . "String 1") (1000 . "String
2"))))
A final word in DXF codes below the 1000 area, you use entmod to change
something such as the layer on which an entity resides, but when it comes to
extended entity data that is marked by a -3 sentinel you are responsible for
managing the data within the extended entity area.
Alternatively if you choose to use the activeX interface, it is very simple
as shown in the following sample code:
-
- (vl-load-com)
- (setq a_app (vlax-get-acad-object)
- a_doc (vla-get-ActiveDocument a_app)
- a_reg (vla-get-RegisteredApplications a_doc)
- )
- (vlax-for itm a_reg
- (progn
- (if (= (vla-get-name itm) "APPID1")
- (vla-put-name itm "NEWAPPNAME")
- )
- )
- )
|