Jump to content

Want to Iterate Through a Bunch of Drawings, but Prompt User to Confirm Before Taking Actions on a Drawing


Recommended Posts

Posted

Good Afternoon/Evening/Morning Everybody!

Today I write because I've discovered a funky issue with the Blocks we use to build projects at my workplace. Essentially, some were drawn in mm, others in inches, but very few actually have a INSUNIT value set. So when one goes to insert said blocks, you might get a teeny tinny version or a gargantuan one depending on the settings of the drawing you're plopping them into. 

In order to rectify this issue I've gone and written up a routine that takes an estimate of the area (using Lee Mac's wonderful minboundingbox function) to decide if that block was drawn in inches or millimeters. This works only because I found the range of areas earlier and there's a very clear difference between the two; as one might imagine when comparing in^2 to mm^2

But I digress, the real issue I have is that I want to prompt the user (which will be me) to confirm if I want to set a value for INSUNITS or not, as some of the blocks don't need the units declared for one reason or another (and also I'd like the prompt to pace the program and give me a chance to read what's getting output to the commandline.)

When I wrote this routine my method was to generate a script file on the fly and use that to iterate through, but I completely overlooked that one cannot pause for input when using script files. Any suggestions/alternate methods for how to get said prompt? 

Attached is the lsp file. First two functions are the meat and potatoes, everything after are support functions. Thanks ahead of time!

set units.lsp

Posted (edited)

As a non-Lisperatti,, and yet aspiring to help...

Are you familiar with the commandline command      " -dwgunits"

YES, the leading hyphen is important, and needs to be included.

Expand your commandline window to about 6 or 8 lines, to better understand all of the options which are available,

and give you an accurate overview.

It is a very powerful command, read all the options and go slowly.

 

Take it around the block and kick the tires before running it on the real files,

but it might be a command which you could include in a script, and run on all of your blocks.

 

Consistency is important, there must be an in house company standard, right?

Or should I say, there SHOULD be?

 

Maybe you need them in both metric and Imperial?

You could do that too, or UNITLESS?

 

I hope that might help.  :beard:

Edited by Dadgad
afterthought
  • Like 1
  • Thanks 1
Posted

As you say if blocks are a mix then a problem. The solution appears to be 2 steps not one.

 

You should be able to stop in your script, been a while, generally its no user input, any way a script can have lisp code in it or call a lisp program that program may have a stop and ask a question. 

 

Only a quick look but add set units.lsp to your Appload Start up suite then the functions will be available.

 

remove the (command ".script" (strcat folderName "\\batchJob.scr")) in batchjob code.

 

Your batchjob1.scr should be,

(BatchJob)

(command ".script" (strcat folderName "\\batchJob.scr"))

 

The script needs (c:UNITSET) to be added after open dwg1 etc in batchjob I think that is what you need. Not tested.

 

open dwg1

(c:UNITSET)

close Y

open dwg2

(c:UNITSET)

close Y

 

You dont need lee's bounding box can just load the boundingbox lisp as part of the script.

  • Like 1
  • Thanks 1
Posted

Hey guys, thanks for replying and trying to help out!

 

10 hours ago, Dadgad said:

-dwgunits

 

Aw man, this looked real promising then I go into BricsCAD only to see they don't have an equivalent implemented 🙃

Brics has been great to me until this moment lol.

 

@BIGAL

I'm honestly really struggling to keep up with what you're suggesting. It just ain't clicking for me and idk why :ouch:

So far I have the lisp being loaded on doc open but the rest is a bit lost on me. Is the idea to make different scriptfiles? 

 

Anyways I'm brainstorming right now and I'm starting to wonder if I might be better off writing the list of drawings to a csv. 

Then start iterating through by checking the first element of that csv, opening the dwg with that filename, and once the lisp is done delete that first entry and open the next one. Placing the relevant calls on bricsCAD's on-doc-load.lsp functionality. Gonna try getting this going. 

 

 

Posted
1 hour ago, Kreaten_vhar said:

Aw man, this looked real promising then I go into BricsCAD only to see they don't have an equivalent implemented 🙃

Brics has been great to me until this moment lol.

 

0 = imperial

1 = metric

 image.thumb.png.5f945711b858abc3aea7c280d6ce2536.png 


 

 

image.thumb.png.e7f205f84ac6f12c1db8e088469f5310.png

 

  • Like 2
Posted

 

2 hours ago, Kreaten_vhar said:

Anyways I'm brainstorming right now and I'm starting to wonder if I might be better off writing the list of drawings to a csv. 

Then start iterating through by checking the first element of that csv, opening the dwg with that filename, and once the lisp is done delete that first entry and open the next one. Placing the relevant calls on bricsCAD's on-doc-load.lsp functionality. Gonna try getting this going.

 

I've decided to go down a rabbithole trying to implement something similar to this idea instead of using scripts.  I take the list of DWG's, take the first element with a car, then set the variable holding the list to the cdr of itself to get rid of the first element I don't need. Then the routine opens the filename that was stored on the first element of the list. Once the new drawing is open on_doc_load.lsp, BricsCAD's equivilent to Acaddoc.lsp, loads my .lsp file and initiates the routine to update the new drawing and read and update the list of drawings in the txt file.

Well at least it should. on_doc_load just seems to fail to load the lsp routine after a couple go's at it. Kinda clueless how to proceed, it's located in a supported path and everything... :bloodshot:

Posted (edited)

Said screw it and decided to use AHK to type in the (load "blahblah.lsp") and call the function on the commandline of the newly open drawing since on_doc_load.lsp don't wanna work. Adds an additional keypress for each drawing I iterate through, but screw it, it works.:surrender:

Edited by Kreaten_vhar
words and grammar fix
  • Like 1
Posted

I have a custom lisp with all my defuns in it so load on start up. (defun C:zzz ( / ) (load "blahblah.lsp")). See Autoload.lsp below

 

Appload.

 

image.png.07dd9d7715afe62ecc633260c37a73cb.png

 

 

  • Like 2
Posted

Ooo that's pretty nifty. 

Posted (edited)

This is my on on_doc_load.lsp for BricsCAD in "C:\...\BricsCAD\Support"

to help keeping a standard between drawings.

 

(setvar 'cmdecho 0)
(setvar 'INSUNITS 1)        ; Sets the Drawing units to inches
(setvar 'THICKNESS 0) 	    ; Sets THICKNESS TO 0
(setvar 'CECOLOR "BYLAYER") ; Sets color property to "BYLAYER."
(setvar 'CELTYPE "BYLAYER") ; Sets linetype property to "BYLAYER."
(setvar 'CELWEIGHT -1)      ; Sets the lineweight to "BYLAYER."
(setvar 'CELTSCALE 1)       ; Sets the LTScale of new objects to 1.
(setvar 'plinetype 2)       ; convents all 2D polylines to optimized polylines  
(setvar 'auprec 4)          ; angular unit percision 0.0000
(setvar 'luprec 4)          ; linear unit percision 0.0000
(setvar 'selectionmodes 0)  ; Set Selection mode to 0
(setvar 'lunits 2)   	    ; Set Linear units to Decimal
(setvar 'perspective 0)	    ; Turn off Perspective view in current viewport
;(setvar 'saveformat 8)      ; Set save to 2010 DXF ;might not want this one. have it set for cnc software we use
(setvar 'nomutt 1)
(vl-cmdf "_.Style" "Standard" "Consolas" "" "" "" "" "")
(setvar 'nomutt 0)
(setvar 'cmdecho 1)

 

 

Edited by mhupp
saveformat commented out
  • Like 2
Posted

Likewise I have a similar LISP on startup, the variables I like to use (might be stealing some of that list) and loading the LISPs I most often use.

 

Taking BigAls LISP a bit further, I have one "Appreload" which loads all the LISP files in my library, which could also be run at start up, can be modified to princ each lisp file name as it loads

 

(defun c:appreload ( / lspname myfiles acount mylistlength Failedtoload)
;;Re-load named LISP files

  (setq mylispfolder  "C:\\Users\\wherever\\")   ;;;;;; change this line ;;;;;;;;;

;;;;;;; edit for laptop ;;;;;;; Laptop maps company driver differently to desktop so added this
  (if (= (findfile "C:\\Users\\wherever\\SIMPLELISP.lsp") nil)  ;;;; if it can find this file do nothing.. use anyfile in your library
    (setq mylispfolder "C:\\Users\\lapTop File Location\\")
  )


  (setq myfiles (vl-directory-files mylispfolder "*.lsp" nil)) ;;myfiles is list of files in mylispfolder location
  (setq mylistlength (length myfiles)) ;;count of number of lsp files

  (setq acount -1)
  (repeat mylistlength
    (setq acount (1+ acount))
    (setq FailedtoLoad (strcat (nth acount myfiles) " failed to load"))
    (load (strcat mylispfolder (nth acount myfiles)) FailedtoLoad) ;;Loads each LISP file
  )

  (princ "\n")
  (princ mylistlength)
  (princ " lsp files loaded from ")
  (princ mylispfolder)
  (princ)

)

 

 

 

 

and one for mhupp, snaps (AutoCAD, not sure if Bricscad does it the same way?

 

;;Snaps. ( * 1.. to use snap, ( * 0 to turn off snap.
    (setq snaps 0)
    (setq snaps (+ snaps (* 1 0)))	;None
    (setq snaps (+ snaps (* 1 1)))	;End Point
    (setq snaps (+ snaps (* 1 2)))	;Mid Point
    (setq snaps (+ snaps (* 1 4)))	;Centre
    (setq snaps (+ snaps (* 0 8)))	;Node
    (setq snaps (+ snaps (* 0 16)))	;Quadrant
    (setq snaps (+ snaps (* 1 32)))	;Intersection
    (setq snaps (+ snaps (* 0 64)))	;Insertion
    (setq snaps (+ snaps (* 0 128)))	;Perpendicular
    (setq snaps (+ snaps (* 1 256)))	;Tangent
    (setq snaps (+ snaps (* 0 512)))	;Nearest
    (setq snaps (+ snaps (* 0 1024)))	;Geometric Centre
    (setq snaps (+ snaps (* 1 2048)))	;Apparent Intersection
    (setq snaps (+ snaps (* 0 4096)))	;Extrnsion
    (setq snaps (+ snaps (* 0 8192)))	;Parallel
    (setq snaps (+ snaps (* 0 16348)))	;Superess all running snaps
  (setvar 'osmode snaps)

 

  • Like 2
Posted (edited)

How I set the snaps I like.

;;----------------------------------------------------------------------------;;
;; Set Osnaps to Endpoint, Middle, Center, Quad, Insertion, Intersection
(defun C:OS ()
  (setvar 'osmode 119)
  (prompt "Osnap Settings set")
  (princ)
)

 

--edit

And I have a hotkeys for tangent, perpendicular, & Geometric center

Edited by mhupp
  • Like 1
Posted (edited)
On 6/24/2022 at 8:05 AM, mhupp said:

to help keeping a standard between drawings.

Edited out for Privacy in the long-run

Edited by Kreaten_vhar
  • Like 1
Posted (edited)

Kreaten_vhar what industry are you in ?

 

Stepehen P my autoload.lsp has just that "Autoload" is a valid command it only loads the lisp when you type its command name.

 

(autoload "COPYCOMMAND" '("ZZZ")) so only loads when you type zzz

Edited by BIGAL
  • Like 1
Posted
14 hours ago, Kreaten_vhar said:

Also being a CAD noob myself

 

Not that much of a noob if you recognize the importance of standards.

  • Like 1
Posted (edited)
On 6/25/2022 at 1:36 AM, BIGAL said:

Kreaten_vhar what industry are you in ?

Edited this out for privacy in the longrun.

 

 

On 6/25/2022 at 1:54 AM, mhupp said:

Not that much of a noob if you recognize the importance of standards.

💓💓💓

Edited by Kreaten_vhar
privacy
  • Like 1

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