Jump to content

Recommended Posts

Posted

Hello everyone, I wanted to know if there is any way to change a diesel expression of a field that appears in multiple files without having to change it by hand in each block that appears.

 

The diesel expression is this:

$(substr,$(getvar,dwgname),1,7)

 

What I want is to be able to change the number of characters that I take from the file name, in this case change the number 7.

 

Thank you very much.

Posted

Unfortunately not in LT, unless of course it is just multiple copies of the same block. You stiil need to open each individual drawing and each block definition that contains that field in each of those drawings. Of course depending on you setup you could just try updating the blocks in one drawing and then inserting this new block definition(s) into each drawing and pick the 'update block definition' each time and see if that works (attributes can be difficult).

 

Posted

I imagined that in LT you couldn't.

In AutoCAD what would it be like?

Posted

No idea 🤣 I only use LT. I would imagine that someone could automate the process using Lisp, after all thats why the full version costs 4 times more than LT.

Posted

I hope someone can help me.

Thank you anyway.

Posted

Your profile says you are using LT ? Do you have access to full Autocad and Lisp?

Posted

I have access to AutoCAD and Lisp

Posted

For me the path and drawing name are part of the title block (not an attribute) as it didn't seem to be anything that would ever need to be modified.

If I wanted to change that I'd modify it and update the title block for each of those drawings.

 

How you need to modify it is up to where it is.

Posted

Is there a way to automate the change using Lisp?

That it will ask you how many characters you want it to take from the beginning of the file name or to show up to a certain character that you tell it.

Posted

Change what?

Is it a portion of a random text, mtext, or attribute?

Is it part of a title block or is it an editable attribute of the title block?

Without an attached drawing or a link to one or a very specific description of what you're looking for nobody's going to be able to help you.

Posted (edited)

It is an editable attribute of the title block

 

The diesel expression is this:

$(substr,$(getvar,dwgname),1,7)

 

I need to change the number of characters that it takes from the beginning of the file name (it is the number of the plane)

Edited by Truski
Posted

Guessing there's more than one attribute so lisp would need the block name and attribute tag name to start with.

Just no way to modify an object without a way to identify it first.

Going to need what method you want to create a selection of drawings to be modified next. Just current directory?

Going home now but if you provide enough information someone here may be willing to help you.

Posted

Consider the following example - the selection could be automated if the target block/attribute tag is known, or alternatively, it could search every block attribute for the target field expression and perform a replacement:

(defun c:test ( / e n x )

    (setq n "$(substr,$(getvar,dwgname),1,3)")
    
    (while
        (progn
            (setvar 'errno 0)
            (setq e (car (nentsel "\nSelect field: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null e)
                    nil
                )
                (   (not (wcmatch (cdr (assoc 0 (setq x (entget e)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION"))
                    (princ "\nInvalid object selected.")
                )
                (   (not
                        (and
                            (setq x (cdr (assoc 360 x)))
                            (setq x (dictsearch x "ACAD_FIELD"))
                            (setq x (dictsearch (cdr (assoc -1 x)) "TEXT"))
                            (setq x (cdr (assoc 360 x)))
                            (setq x (entget x))
                            (= "FIELD" (cdr (assoc 0 x)))
                            (= "AcDiesel" (cdr (assoc 1 x)))
                        )
                    )
                    (princ "\nThe selected object does not contain a DIESEL field expression.")
                )
                (   (entmod
                        (subst
                            (cons 2 (strcat "\\AcDiesel " n))
                            (assoc 2 x)
                            (subst (cons 1 n) (assoc 1 (member (assoc 6 x) x)) x)
                        )
                    )
                    (command "_.regenall")
                )
            )
        )
    )
    (princ)
)

 

  • Like 1
Posted

Hi @Lee Mac, I have tested your lisp and it works great.

I want to automate the change in many plans and layouts.

Can it be done without having to select the block?

Thank you.

 

9 hours ago, Lee Mac said:

Consider the following example - the selection could be automated if the target block/attribute tag is known, or alternatively, it could search every block attribute for the target field expression and perform a replacement:


(defun c:test ( / e n x )

    (setq n "$(substr,$(getvar,dwgname),1,3)")
    
    (while
        (progn
            (setvar 'errno 0)
            (setq e (car (nentsel "\nSelect field: ")))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null e)
                    nil
                )
                (   (not (wcmatch (cdr (assoc 0 (setq x (entget e)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION"))
                    (princ "\nInvalid object selected.")
                )
                (   (not
                        (and
                            (setq x (cdr (assoc 360 x)))
                            (setq x (dictsearch x "ACAD_FIELD"))
                            (setq x (dictsearch (cdr (assoc -1 x)) "TEXT"))
                            (setq x (cdr (assoc 360 x)))
                            (setq x (entget x))
                            (= "FIELD" (cdr (assoc 0 x)))
                            (= "AcDiesel" (cdr (assoc 1 x)))
                        )
                    )
                    (princ "\nThe selected object does not contain a DIESEL field expression.")
                )
                (   (entmod
                        (subst
                            (cons 2 (strcat "\\AcDiesel " n))
                            (assoc 2 x)
                            (subst (cons 1 n) (assoc 1 (member (assoc 6 x) x)) x)
                        )
                    )
                    (command "_.regenall")
                )
            )
        )
    )
    (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...