Jump to content

Import point + text on different layer lisp


Lukepeanuts

Recommended Posts

Hy,

 

im a rookie with lisp, so i need an help (a big one) to complete a lisp.

I have an external txt file with a lot lines. The columns are in this way:

 

1st COLUMN: PROGRESSIVE NUMBER
2nd COLUMN:	x COORDINATE
3rd COLUMN: 	y COORDINATE	
4th COLUMN: 	z COORDINATE		
5th COLUMN:  DESCRIPTION

 

and i need to create in autocad a point with the coordinate and three texts at his side: the point and the texts must be on different layers and i need a separate block for every point with its texts (a block for every line of the external file).

 

my idea was something like this:

 

IMPORT POINT + TEXT LISP
1-	IF THE LAYER DOESN’T EXIST: CREATE LAYER “LEV BLOCK” (INDEX COLOR YELLOW: 2)
2-	IF THE LAYER DOESN’T EXIST: CREATE LAYER “LEV POINT” (INDEX COLOR YELLOW: 2)
3-	IF THE LAYER DOESN’T EXIST: CREATE LAYER “LEV TEXT NUMBER” (INDEX COLOR YELLOW: 2)
4-	IF THE LAYER DOESN’T EXIST: CREATE LAYER “LEV TEXT Z” (INDEX COLOR GREEN: 3)
5-	IF THE LAYER DOESN’T EXIST: CREATE LAYER “LEV TEXT ANNOTATION” (INDEX COLOR RED: 1)

6-	COMMAND “PDMODE” “32”
7-	SETQ “HEIGHTofTEXT”
8-	HIDE OBJECTS: ALL

9-	CURRENT LAYER: LAYER “LEV POINT” 
10-	CREATE POINT (IMPORT FROM EXTERNAL FILE THE COORDINATE (1st LINE: 2nd COLUMN 3rd COLUMN, 4th COLUMN)
11-	CURRENT LAYER: LAYER  “LEV TEXT NUMBER”
12-	CREATE MTEXT (IMPORT FROM EXTERNAL FILE THE COORDINATE (1st LINE: 2nd COLUMN+“HEIGHTofTEXT”*1.5,  3rd COLUMN+“HEIGHTofTEXT”*1.5, 4th COLUMN)(TEXT HEIGHT “HEIGHTofTEXT”)(TEXT: NUMBER IN THE 1st COLUMN)
13-	CURRENT LAYER: LAYER  “LEV TEXT Z”
14-	CREATE MTEXT (IMPORT FROM EXTERNAL FILE THE COORDINATE (1st LINE: 2nd COLUMN+“HEIGHTofTEXT”*1.5,  3rd COLUMN, 4th COLUMN)(TEXT HEIGHT “HEIGHTofTEXT”)(TEXT: NUMBER IN THE 4th COLUMN)
15-	CURRENT LAYER: LAYER  “LEV TEXT ANNOTATION”
16-	CREATE MTEXT (IMPORT FROM EXTERNAL FILE THE COORDINATE (1st LINE: 2nd COLUMN+“HEIGHTofTEXT”*1.5,  3rd COLUMN-“HEIGHTofTEXT”*1.5, 4th COLUMN)(TEXT HEIGHT “HEIGHTofTEXT”)(TEXT: TEXT IN THE 5th COLUMN)

17-	CURRENT LAYER: LAYER “LEV BLOCK” 
18-	SELECT: ALL
19-	CREATE BLOCK
20-	HIDE OBJECTS: ALL

21-	REPEAT FROM 9 TO 20 FOR ALL THE LINES IN THE EXTERNAL FILE

22-	UNHIDE OBJECTS

 

I started to write the lisp and i arrive at the point 9 in this way:

 

(defun C:LEV ()
 
 (command "_.layer" "_MAKE" "LEV BLOCK" "COLOR" "2" ""
  "_MAKE" "LEV POINT" "COLOR" "2" ""
  "_MAKE" "LEV TEXT NUMBER" "COLOR" "2" ""
  "_MAKE" "LEV TEXT Z" "COLOR" "3" ""
  "_MAKE" "LEV TEXT ANNOTATION" "COLOR" "1" "" "")
   
  (COMMAND "PDMODE" "32" "")
  (COMMAND "HIDEOBJECTS" "ALL" "")
  (COMMAND "_.CLAYER" "LEV POINT" "")

(PRINC)  
)

 

From here i dont know how to import the coordinate to create the points, the coordinate to create the text (my idea is to use the coordinate of the point and move a little bit the text on the right using the height of the text X a number)

 

Somebody can help me? I will appreciate a lot.

Link to comment
Share on other sites

A good ideas is write a little defun that checks for the layer and add that to an autoloading lisp like acaddoc.lsp this way its available for any program you write. Items 1-5

(laynew "lev_block" 2 "Continuous")

 

lee-mac has a good read line lisp that can make a list using a delimeter normally it would use the "," or a CSV file but you can use a space etc. If your columns are fixed length always then you can use substr start end to read the number of characters.

 

If you post a sample file it will confirm what your data file looks like, what you are asking for has been done many times only variation is the different layers.

 

Check out http://www.Lee-mac.com point manager.

 

Another you can set variables directly like current layer (setvar 'clayer "TEXT") pdmode osmode filletrad to mention a few without using Command.

Edited by BIGAL
Link to comment
Share on other sites

Here is a simple make layer save it to say a autoloading lisp like acaddoc.lsp

 

(defun mynewlayer ( layname col lt / )
(if (or (= lt "C")(= lt "c"))(setq lt "Continuos")) ; shorthand typing in calling code
(if (= (tblsearch "layer" layname) nil)
(command "_.layer" "_MAKE" layname "COLOR" col "" "LT" lt "" "")
)
)
; in program
; (mynewlayer "BIGAL" 3 "c")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...