Jump to content

Recommended Posts

Posted

Hi, I tried to write an autolisp code and I got to a certain point, but it is not working as I wanted. I would like your suggestions and your support in revising the code.

 

What I want to do is select a block. To find out which character (n) from the right is the "-" sign in the layer name of the line touching the block I selected. Then subtract 1 from this character(n) number and add n-1 from the right. Combining the part up to the character and the prefix text and writing to the block geometric point.

 

The way this code works now is to combine the front text and the text to the right of the "-" sign of the last layer added to the layer list and write it to the center of the block. This wasn't something I wanted.

 

(setq *textHeight* 8)
(setq *layerName* "01 Equipment list 2")
(setq *textColor* 1) ; 

(defun c:bs_ayar ()
  (setq *textHeight* (getreal "\nEnter new text height: "))
  (setq *layerName* (getstring "\nEnter new layer name: "))
  (setq *textColor* (getint "\nEnter new color index (1 for Magenta): "))
  (princ (strcat "\nText height is now " (rtos *textHeight*) ", layer name is " *layerName* ", color is " (itoa *textColor*) " was set to. "))
  (princ)
)

(defun c:bs4 ()
  (setq prefix (getstring T "\nEnter prefix letter: "))
  (setq blk (car (entsel "\nSelect Block: ")))
  (setq blkEnt (entget blk))
  (setq insPt (cdr (assoc 10 blkEnt)))

  (setq ss (ssget "_X" (list (cons 0 "LINE,POLYLINE"))))
  (if (and ss (> (sslength ss) 0)) 
    (progn
      (setq line (ssname ss 0))
      (setq lineEnt (entget line))
      (setq lineLayer (cdr (assoc 8 lineEnt)))
      (setq dashPos (vl-string-search "-" lineLayer))
      (if dashPos
        (setq rightPart (substr lineLayer (+ dashPos 2)))
        (setq rightPart lineLayer)
      )
      (command "._-LAYER" "_M" *layerName* "" "_C" *textColor* "" "")
      (command "._TEXT" insPt *textHeight* "" (strcat prefix rightPart))
      (command "._-LAYER" "_S" *layerName* "")
    )
    (princ "\nNo line or polyline was found touching the selected block.")
  )
  (princ)
)

 

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...