Jump to content

LTSCALE 1.0 to AllOpenedDwgs


zwonko

Recommended Posts

Trying to make lisp to change LTSCALE to 1.0 to all open drawings. In other topic 

 

 

(defun c:S2L ( / )
 (vlax-for OpenDwgs (vla-get-documents (vlax-get-acad-object))
   (vla-setvariable OpenDwgs "TILEMODE" 0)
 );; vlax-for
 (princ)
)

 

 

Tried to modify it but is not working. Changing    

(vla-setvariable OpenDwgs "LTSCALE" 1)

do nothing, only first drawing is changed. Also tried:  

 (vla-SendCommand OpenDwgs (strcat "LTSCALE" " " "1" " "))

Still nothing.

I read that ltscale working only to current active dwg, so I tried to add.

(vla-activate OpenDwgs)

Tried some more but still nothing is happend.

 

Could somebody help?

Link to comment
Share on other sites

This should be what your looking for.

 

(defun C:S2L (/ x)
  (vl-load-com)
  (vlax-for x (vla-get-documents (vlax-get-acad-object))
    (vla-activate (vla-item (vla-get-documents (vlax-get-acad-object)) (vla-get-name x)))
    (setvar 'LTSCALE 1) ;fixed typo
  )
  (princ)
)

 

https://forums.augi.com/showthread.php?113272-list-all-open-drawings

https://www.theswamp.org/index.php?topic=40319.0

Edited by mhupp
changed to setvar
Link to comment
Share on other sites

First try, error in loading lisp:

Error: malformed string on input
Error: malformed list on input
Error: malformed list on input

 

Second, changed 'LTSCALE" to "LTSCALE".

Error: Automation error - "Item"

 

Tried other options like in first post and still automation error

Link to comment
Share on other sites

Quote

(setvar 'LTSCALE 1)

Had a typo this should work. but change this to what ever you need to change the line scale to 1

 

Edited by mhupp
Link to comment
Share on other sites

The problem is that normally i can change LTS. by typing "lts" "ltscale" "setvar ltscale". After changing it by my or Your lisps the variable is not changing. Lets say that I set it to 30, use lisp, type lts and it still is 30. Should be 1 even if what You mention above (msltscale or celtscale)

Link to comment
Share on other sites

I don't know just ran a test on my end everything seems to be working properly.

Are all your drawings in the same window/instance of Autocad? or do they have their own windows? that might be the problem.

I opened up a Test-LT20 in a diffrent instance and it didn't run with the rest of the drawings.

 

image.png.0073cd50c5d5e6495d83c998e8b9e4d0.png

 

(defun C:S2L (/ x)
  (vl-load-com)
  (vlax-for x (vla-get-documents (vlax-get-acad-object))
    (vla-activate (vla-item (vla-get-documents (vlax-get-acad-object)) (vla-get-name x)))
    (prompt (strcat "\n======================"))
    (prompt (strcat "\n" (getvar "dwgname")))
    (prompt (strcat "\nLTS Before: " (rtos (getvar 'LTSCALE) 2 0)))
    (setvar 'LTSCALE 1) ;fixed typo
    (prompt (strcat "\nLTS After: " (rtos (getvar 'LTSCALE) 2 0)))
  )
  (princ)
)

 

======================
Test-LTS5.dxf
LTS Before: 5
LTS After: 1
======================
Test-LTS2.dxf
LTS Before: 2
LTS After: 1
======================
Test-LTS10.dxf
LTS Before: 10
LTS After: 1

Link to comment
Share on other sites

The drawings are in same window (in cards). There is only one CAD program running.

I don't know what the point, maybe is system thing?

Tried it on two computers:

1) ZWCAD 2021 +win10

2) Autocad 2014+win10


 

AUTOCAD:

When I run the program it is jumping form first opened drawing to second. After clicking back to first it get the result:

Drawing2.dwg
LTS Before: 1
LTS After: 10
======================
Drawing2.dwg
LTS Before: 10
LTS After: 10
======================
Drawing2.dwg
LTS Before: 10
LTS After: 10

 

So it looks like it changing only the first drawing, times number of opened drawings. Tried knew drawings, not saved drawings, or drawings in dwg still its warking like above. That in Autocad 2014.

 

On ZWCAD im getting like:

======================
Drawing1.dwg
LTS Before: 1
LTS After: 10

 

So the only first drawing is changed. After that sometimes getting Automation erro - Item

Link to comment
Share on other sites

The suggested code works in BricsCAD. But in AutoCAD a Lisp routine is restricted to run in a single document.

 

Try this:

(defun C:S2L (/ x)
  (vl-load-com)
  (vlax-for x (vla-get-documents (vlax-get-acad-object))
     (vla-setvariable x "LTSCALE" 1)
  )
  (princ)
)

 

Link to comment
Share on other sites

1 hour ago, Roy_043 said:

The suggested code works in BricsCAD. But in AutoCAD a Lisp routine is restricted to run in a single document.

 

Try this:


(defun C:S2L (/ x)
  (vl-load-com)
  (vlax-for x (vla-get-documents (vlax-get-acad-object))
     (vla-setvariable x "LTSCALE" 1)
  )
  (princ)
)

 

 

His first post said he tried that already.

Link to comment
Share on other sites

As far as I understand it, in AutoCAD a LISP routine will only work in the drawing where it is called. If you switch from drawing A to drawing B you don't take the running LISP with you. This makes sense if you consider you might have a complex LISP to run on drawing A so while it runs you switch to drawing B to do stuff... you don't want the LISP to jump to drawing B and change things there. You can't quite do what you want.

 

So in the past I have made up a script routine - open a drawing - do stuff - close a drawing - open the next drawing - and so on as a part of a script. I think since it is a script it works outside of the drawing and can then do stuff on several drawings. Lee Mac and others have script writing tools, and you can also look at the core console. They do it better than me,

 

I think this:

(command "_.SCRIPT" tempscript)

is the line that runs a script from a drawing and tempscript in this case is the filepath and script name (including .scr suffix)... you just have to make that up. In the script (tempscript.scr) I specify which drawings to open and close plus all the commands. Noting here that I made this up a while ago and forget how it works but I also know it is not in a fit state to share, sorry.

 

The one drawback I have is I never managed to get it to work on open drawings - I tried a bit but never quite got there. I think I needed to close each drawing before moving to the next one or something like that, I'd have to close the open drawings. If anyone know if you can alter open drawings with a script I'd like to update this.

 

That might help but you can't do it on open drawings.. I think

 

 

 

I think I did read that you can use VLA- commands between drawings in the way you want - wasn't any good for me - so you could have a go and see if you ca rework what you need just using that (try it forst with a simple VLA- command and see what happened)

Link to comment
Share on other sites

2 hours ago, Roy_043 said:

The suggested code works in BricsCAD. But in AutoCAD a Lisp routine is restricted to run in a single document.

 

Try this:


(defun C:S2L (/ x)
  (vl-load-com)
  (vlax-for x (vla-get-documents (vlax-get-acad-object))
     (vla-setvariable x "LTSCALE" 1)
  )
  (princ)
)

 

Still nothing. It must be something with this LTSCALE. Because if i changed to for example gripobjlimit and it works. 

 

@Steven P, Lisp can work in separate files if You told them to do :) the point was to do it on all opened drawings by just one command. That, what You said is getting me to Lee Mac scriptwriter, what of course I can do, but takes a little bit more :) (and also I forget about scriptwriter when i had to change this LTSCALE in few drawings :P )

 

I think that now everyone had done what they could. Let's left it like that :)

 

There are plenty of other lisps to do :)

 

Thanks all You guys!

Link to comment
Share on other sites

3 hours ago, Roy_043 said:

The suggested code works in BricsCAD. But in AutoCAD a Lisp routine is restricted to run in a single document.

That works for me in CAD 2020 as I used to do the same process in my daily routines.

Link to comment
Share on other sites

I dont like scripts

1 its too easy for them to mess up

2  I hope you dont have epilepsy you know what i mean once you run this.

3 might want to wirte in a stopgap like if blkLst is over 20 in lenght ask if you want to continue

Ran this on a folder that had over 5000 blocks had to Alt F4 because you cant stop once it runs or i don't know how.

 

;;----------------------------------------------------------------------------;;
;; Make script file for drawings in a folder
  (defun c:LTS (/ Path UserFile blkLst F1 FileName)
    (vl-load-com)
    (setq Path (strcat (getvar 'DWGPREFIX))
          UserFile (getfiled "Choose a Folder to Process" Path "*" 16)
          Path (vl-filename-directory UserFile)
          blkLst (vl-directory-files Path "*.dwg" 1)
          blkLst (append blkLst (vl-directory-files Path "*.dxf" 1))  ;remove this if you don't use dxf files
          blkLst (vl-sort blkLst '<) 
          F1 (open (strcat (getenv "userprofile") "\\Documents\\Script.scr") "w")
    )
    (if (= nil blkLst)
      (prompt "\nNo Drawings Found in Folder")
      (foreach FileName blkLst
        (princ (strcat "_.open \"" Path "\\" FileName "\"\n") F1)
        (princ "_.LTSCALE 1\n" F1)
        (princ "_.qsave\n" F1)
        (princ "_.close\n" F1)
      )
    )
    (close F1)
    (prompt (strcat "\nScript File for " (itoa (length BlkLst)) " Files Created"))
    (vl-cmdf "_.Script" (strcat (getenv "userprofile") "\\Documents\\Script.scr")) 
    (princ)
  )

 

Link to comment
Share on other sites

Ok, the following code works for me:

(defun C:S2L (/ x)
  (vl-load-com)
  (vlax-for x (vla-get-documents (vlax-get-acad-object))
	(vla-SendCommand x (strcat "LTSCALE" " " "1" " "))
	(vla-SendCommand x (strcat " " " " ))
  )
  (princ)
)









 

But is it JUMPY.

Lets said that first "card" of drawings is Drawing1, next Drawing2, Drawing3, Drawing4etc. I run Sl2, and the program jump to drawing2. Now i click on Drawing1, and it jumps to drawing2, netx click on drawing1 and it jumps to drawing3. So if I had drawing1-4 i must click drawing 1 8times, and the LTS is changed.

Link to comment
Share on other sites

It is possible but be warned it could go into a continous loop uses 2 lisps one to start the second does the work in this case had multi dwgs set to model and they jump to "layout1" take the crash now out if happy.

 

; start lisp
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(setq numlay (vla-get-count acdocs))
(setenv "num" "0")
(load "d:\\acadtemp\\test.lsp")
; test.lsp
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(vla-activate (vla-item acdocs (atoi (getenv "num"))))
(setvar 'ctab "Layout1")
(setenv "num" (rtos (+ (atoi (getenv "num")) 1) 2 0))
(if (> (atoi (getenv "num"))) (vla-get-count acdocs)(exit))
(alert "crash now")(if (= (getstring "press enter to continue any key exit") ")(princ)(exit))
(load "d:\\acadtemp\\test.lsp")

 

Link to comment
Share on other sites

for me this simple code worked as expected

 

(vlax-for d (vla-get-documents (vlax-get-acad-object)) (vla-setvariable d "LTSCALE" 0.5))

 

so if it's not the code , maybe it's your AutoCad installation or your drawings. Yould try on a different computer or check your drawings with audit or something. Every now and again (rarely but it happens) I have a drawing that defies all logic (like my wife) and then I open a blanc , copy / paste entities in new drawing and saveas (doesn't work on the wife though)

 

Stupid question but I assume you check the setting before closing / after saving?

 

And if the only stable way is using a script , so what? If it gets the job done , you're still a winner / the only one losing sleeping about it is you ;-)

 

Sometimes the journey is more important than the destination and sometimes its just the end result that counts :winner:

 

:beer:

 

🐉

Link to comment
Share on other sites

Yes, I will just make it by scriptwirter nex time :)

I dinn't exacly check what happend after closing/saving. But checked by typing LTS after lisp running every drawing few times. You think that just simple ctrl+s can do the job?

I checked on two computers. Have no more :P

Drawings were made new. Also checked on dxf, also on old drawings.

 

EDIT: Check, saving/closing is not changing anything.

Edited by zwonko
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...