jan_ek 发表于 2022-7-6 08:05:31

[Autolisp] - Download data - q

Hello.
I use this feature:

(defun nnnn (nek / ss dana)(if (setq ss (ssget "x" (list (cons 0 "text,mtext") (cons 8 nek))))        (setq dana (dxf 1(entget (ssname s 0))))        (setq dana "0" ))        (if (numberp dana)                (setq dana (rtos dana 2 2))                (setq dana dana)        )                (princ (strcat "\n " nek " --> " dana))dana)(defun c:wer ( / a b c d)(setq a (nnnn "layer1"))(setq b (nnnn "layer2"))(setq c (nnnn "layer3"))(setq d (nnnn "layer4")).....)
Sure, it can be easier to write so please help. Sure, it can be avoided in some way to repeatedly search the drawing database, but do not know how. This function is used to download the text of a particular layer.

BlackBox 发表于 2022-7-6 08:21:42

Forgive me, but it is hard to understand what it is you're asking for exactly...
 
I believe that you're wanting a sub-function that accepts a layer name argument as string, and are attempting to return a list of text strings for all Mtext and Text entities on the argument layer. If so, these may help:
 
This example uses DXF code -

(defun GetTextStringsByLayer (layerName / ss e textStrings) ;; Example: (GetTextStringsByLayer "SomeLayer") (if (and (tblsearch "layer" layerName)      (setq ss (ssget "_x" (list '(0 . "MTEXT,TEXT") (cons 8 layerName)))))   (progn   (setq i -1)   (while (setq e (ssname ss (setq i (1+ i))))       (setq textStrings (cons (cdr (assoc 1 (entget e))) textStrings)))))
 
This example uses vla-* TextString Property -

(defun GetTextStringsByLayer (acDoc layerName / ss) ;; Example: (GetTextStringsByLayer (vla-get-activedocument (vlax-get-acad-object)) "SomeLayer") (if (and (= 'VLA-OBJECT (type acDoc))          (tblsearch "layer" layerName)          (setq ss (ssget "_x" (list '(0 . "MTEXT,TEXT") (cons 8 layerName)))))   (progn   (vlax-for oText (setq ss (vla-get-activeselectionset acDoc))       (setq textStrings (cons (vla-get-textstring oText) textStrings)))   (vla-delete ss))))
 
HTH

jan_ek 发表于 2022-7-6 08:27:48

I use this function:
"(nnnn "layer1")" about 40 times in my program.
Each time searching the base drawing.
The question is: is it necessary, it may be easier.

Tharwat 发表于 2022-7-6 08:41:30

 
What does the routine do ?
What is your aim of the code ?
 
Explain your needs clearly to get the accurate answer

BlackBox 发表于 2022-7-6 08:52:32

Without more information it is hard to know for sure... However, redundancy is generally not a good practice, unless necessary.
 
If the purpose of your function is extract information, then simply store the extracted information to a variable and query, or manipulate the variable thereafter.

irneb 发表于 2022-7-6 08:58:29

Just as long as that "data" is not a selection set. From the OP it seems to be. I'd highly advise against saving a selection set into a global variable. 
From the nnnn function it appears you simply want to list the 1st text placed on the specified layer - to the command line. You might save just that text's ename, but then what if it's erased / changed to a different layer?
 
Again, we require some more info on what you're trying to accomplish. We might be pointing you into a direction which could cause problems down the line. It's for your own benefit to explain as clearly as possible for us hard-of-understanding people

jan_ek 发表于 2022-7-6 09:07:55

Sorry it's probably the language difficulties.
The idea is this:
- Creating drawings of interest to me put the data on specific layers.
- Then using Lisp takes this data and somehow, further transformed (multiplying, dividing by typing in other places).
页: [1]
查看完整版本: [Autolisp] - Download data - q