Jump to content

[Autolisp] - Download data - quickly, simply


Recommended Posts

Posted

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.

Posted

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

Posted

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.

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

 

What does the routine do ?

What is your aim of the code ?

 

Explain your needs clearly to get the accurate answer

Posted

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.

Posted
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.
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 :roll:

Posted

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

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