JimYuan's Blog

Sharing the things I learned

0%

RetrieveGraphInfo_InAutoCAD_autoLISP

Reference

  • entsel : prompts the user to select a single object(entity) by specifying a point
  • car
  • cdr
  • entget

entsel

1
(setq en1 (entsel))

If you want to prompt user with a sentence

1
(setq e (entsel "Please choose an object: "))

More about entsel

Return value:

A list whose first element is the entity name of the chosen object and whose second element is the coordinates (in terms of the current UCS) of the point used to pick the object.

The pick point returned by entsel does not represent a point that lies on the selected object.

car

1
(car en1)

In the previos example, (car en1) here will return the first element in the list, which is the EntityName

cadr

1
(cadr en1)

In the previos example, (car en1) here will return the second element in the list, which is the point location

entget

Retrieves an object’s (entity’s) definition data

1
(setq en1_data (entget (car en1)))

If the entity you selected is in the different types, entget may return different geometry infomation.

群碼分析表

Group Codes by Name

If the graph info pair separated by ., (1 . “ABC”) for example, we need to use cdr to retrieve the secend element, instead of cadr

1
(cons 1 "ABC")

can create an dot pair, (1 . “ABC”)

How to revise the data?

  1. entget to get the entity information

  2. assoc to find the correct group_code string pair. The new string pair can be created by cons

  3. subst to swap/change the new/old string pairs

  4. entmod to renew the autocad canvas and show the new string pair

  5. !ent_data

  6. (setq oldr (assoc 40 en1_data))

  7. (setq newr (cons 40 23.8))

  8. (setq en1_data (subst newr oldr en1_data))

  9. (entmod en1_data)

  • entget
  • assoc: Searches an association list for an element and returns that association list entry
  • subst: Searches a list for an old item and returns a copy of the list with a new item substituted in place of every occurrence of the old
  • entmod