Jump to content

A little help needed.......


KESHAR

Recommended Posts

I have a code that I need a little help with. First things first, I am creating this to try to eliminate the use of incorrect title blocks as well as standard blocks on a project. This will be adapted to all projects so that there is more consistency throughout.

 

 

The problem that I have run into is that I have to hit "enter" between the insertion of both blocks. And after the second block is inserted I get an unknown command error, but everything works.

 

 

Not understanding what I have done wrong. Please see the code below and help shed some light on this for me please.

 

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;Created by Karl E Sharp 7/3/2018
;;
;;Designed to create a default project specific DWG Template with all
;;   project variables set. (i.e. linewght, linetypes, dimstyle, textstyle, texthieght, etc.)
;;
;;Inserts project title block and all annotation blocks to be used
;;
;;Sets SDI mode to 0
;;
;;Turns off attribute Dialog on insertion of block
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
(defun c:NDS (/ d-path)
 (setvar "dimadec" 0)                 ; Angular decimal places
 (setvar "dimalt" 0)                  ; Alternate units selected
 (setvar "dimaltd" 0)                 ; Alternate unit decimal places
 (setvar "dimaltrnd" 0.0000)          ; Alternate units rounding value
 (setvar "dimalttd" 2)                ; Alternate tolerance decimal places
 (setvar "dimalttz" 0)                ; Alternate tolerance zero suppression
 (setvar "dimaltu" 2)                 ; Alternate units
 (setvar "dimaltz" 0)                 ; Alternate unit zero suppression
 (setvar "dimapost" "")               ; Prefix and suffix for alternate text
 (setvar "dimarcsym" 0)               ; Arc length symbol
 (setvar "dimasz" 0.1875)             ; Arrow size
 (setvar "dimatfit" 3)                ; Arrow and text fit
 (setvar "dimaunit" 0)                ; Angular unit format
 (setvar "dimazin" 0)                 ; Angular zero supression
 (setvar "dimblk" "")                 ; Arrow block name
 (setvar "dimblk1" "")                ; First arrow block name
 (setvar "dimblk2" "")                ; Second arrow block name
 (setvar "dimcen" 0.25)               ; Center mark size
 (setvar "dimclrd" 256)               ; Dimension line and leader color
 (setvar "dimclre" 256)               ; Extension line color
 (setvar "dimclrt" 2)                 ; Dimension text color
 (setvar "dimdec" 4)                  ; Decimal places
 (setvar "dimdle" 0)                  ; Dimension line extension
 (setvar "dimdli" 0.0625)             ; Dimension line spacing
 (setvar "dimdsep" ".")               ; Decimal separator
 (setvar "dimexe" 0.0625)             ; Extension above dimension line
 (setvar "dimexo" 0.0625)             ; Extension line origin offset
 (setvar "dimfrac" 2)                 ; Fraction format
 (setvar "dimfxl" 1)                  ; Fixed Extension Line
 (setvar "dimfxlon" 0)                ; Enable Fixed Extension Line
 (setvar "dimgap" 0.0625)             ; Gap from dimension line to text
 (setvar "dimjust" 0)                 ; Justification of text on dimension line
 (setvar "dimldrblk" "")              ; Leader block name
 (setvar "dimlfac" 1)                 ; Linear unit scale factor
 (setvar "dimlim" 0)                  ; Generate dimension limits
 (setvar "dimltex1" "bylayer")        ; Linetype extension line 1
 (setvar "dimltex2" "bylayer")        ; Linetype extension line 2
 (setvar "dimltype" "bylayer")        ; Dimension linetype
 (setvar "dimlunit" 4)                ; Linear unit format
 (setvar "dimlwd" -1)                 ; Dimension line and leader lineweight
 (setvar "dimlwe" -1)                 ; Extension line lineweight
 (setvar "dimrnd" 0)                  ; Rounding value
 (setvar "dimsah" 0)                  ; Separate arrow blocks
 (setvar "dimscale" 1)                ; Overall scale factor
 (setvar "ltscale" 0.5)               ; Linetype scale factor
 (setvar "dimsd1" 0)                  ; Suppress the first dimension line
 (setvar "dimsd2" 0)                  ; Suppress the second dimension line
 (setvar "dimse1" 0)                  ; Suppress the first extension line
 (setvar "dimse2" 0)                  ; Suppress the second extension line
 (setvar "dimsoxd" 0)                 ; Suppress outside dimension lines
 (setvar "dimtad" 1)                  ; Place text above the dimension line
 (setvar "dimtdec" 4)                 ; Tolerance decimal places
 (setvar "dimtfac" 1)                 ; Tolerance text height scaling factor
 (setvar "dimtfill" 1)                ; Text background enabled
 (setvar "dimtad" 1)                  ; Place text above the dimension line
 (setvar "dimtfillclr" 0)             ; Text background color
 (setvar "dimtih" 0)                  ; Text inside extensions is horizontal
 (setvar "dimtix" 0)                  ; Place text inside extensions
 (setvar "dimtm" 0)                   ; Minus tolerance
 (setvar "dimtmove" 0)                ; Text movement
 (setvar "dimtofl" 0)                 ; Force line inside extension lines
 (setvar "dimtoh" 0)                  ; Text outside horizontal
 (setvar "dimtol" 0)                  ; Tolerance dimensioning
 (setvar "dimtolj" 0)                 ; Tolerance vertical justification
 (setvar "dimtp" 0)                   ; Plus tolerance
 (setvar "dimtsz" 0)                  ; Tick size
 (setvar "dimtvp" 0)                  ; Text vertical position
 (setvar "dimtxsty" "standard")       ; Text style
 (setvar "dimtxt" 0.09375)            ; Text height
 (setvar "dimtzin" 0)                 ; Tolerance zero suppression
 (setvar "dimupt" 0)                  ; User positioned text
 (setvar "dimzin" 3)                  ; Zero suppression
 (command "dimstyle" "save" "standard" "y")
 (command "style" "standard" "romans" 0.09375 1 0 "no" "no" "no")
 (command "linetype" "load" "center2" "" "")
 (command "linetype" "load" "hidden2" "" "")
 (command "linetype" "load" "phantom2" "" "")
 (command "layer" "m" "DIM" "c" "1" "DIM" "")
 (command "layer" "m" "TEXT" "c" "2" "TEXT" "lt" "continuous" "TEXT" "")
 (command "layer" "m" "CENTER" "c" "1" "CENTER" "lt" "center2" "CENTER" "")
 (command "layer" "m" "HIDDEN" "c" "2" "HIDDEN" "lt" "hidden2" "HIDDEN" "")
 (command "layer" "m" "MATCHLINE" "c" "3" "MATCHLINE" "lt" "phantom2" "MATCHLINE" "")
 (command "layer" "m" "EQUIP" "c" "3" "EQUIP" "lt" "continuous" "EQUIP" "")
 (command "layer" "m" "LABEL_PLATE" "c" "3" "LABEL_PLATE" "lt" "continuous" "LABEL_PLATE" "")
 (command "layer" "m" "BACKGROUND" "c" "9" "BACKGROUND" "lt" "continuous" "BACKGROUND" "")
 (command "layer" "m" "SYMBOLS" "c" "3" "SYMBOLS" "lt" "continuous" "SYMBOLS" "")
 (command "layer" "m" "VIEWPORT" "c" "7" "VIEWPORT" "plot" "n" "VIEWPORT" "")
 (command "layer" "s" "0" "")
 (command "LUNITS" "4")
 (command "LUPREC" "5")
 (setvar "SDI" 0)                     ; Turns SDI mode off
 (setvar "attdia" 0)                  ; Turns the attribute edit dialog box off for block insertion
 (setvar "attreq" 1)
 (initdia 0)
 (setq filename "S:\\folder-1\\subfolder-1\\filename")
 (if
   (= 0 (getvar "SDI"))
     (command "-insert" "S:\\folder-1\\subfolder-1\\filename" '(0. 0. 0.) "" "" ""))   ; Inserts Client Border
 (while (= (logand (getvar "cmdactive")1)1)
   (command ""))
   (initdia)
 (princ)
  (setq filename "S:\\folder-2\\subfolder-2\\filename")
 (if
   (= 0 (getvar "SDI"))
     (command "-insert" "*S:\\folder-2\\subfolder-2\\filename" '(36. 0. 0.) "" "" )) ; Inserts Company Border with standard annotation blocks
 (while (= (logand (getvar "cmdactive")1)1)
   (command ""))
   (initdia)
 (princ)
)

Edited by KESHAR
Link to comment
Share on other sites

Completely new to this. What should I do instead? I tried removing the command pause and it freezes...... Oh this is making my brain pan hurt :? :/

Link to comment
Share on other sites

Completely new to this. What should I do instead? I tried removing the command pause and it freezes...... Oh this is making my brain pan hurt :? :/

 

 

Well I'm actually feeding my brain with a little anti-freeze , hik ;-)

 

 

but maybe (command "") in stead of (command pause)?

 

 

Also (again without testing) , just from memory (which is slowly getting foggy) , when you insert a block with prefix * , do you still have the same number of prompts? I'm not entirely sure without trying , but I vaguely remember the standard prompts will ask for separate scale for x and y and the other just one scale factor for both.

Link to comment
Share on other sites

Thanks.... that worked for the issue between the insertions..... not sure about the number of prompts for "*" on insertion......gonna check something.....

Link to comment
Share on other sites

vundaba!!!! Thanks for the assistance RLX...... I had one to many quotes on the second insertion....I have edited the above code with the corrections. Trying to get a better handle on all of this so I can truly say that I have learned something new and in the process help out somewhere along the way, and hopefully make my life easier.

Link to comment
Share on other sites

Just out of curiosity, is there a way to condense this down to less coding?

 

 

I'm sure you can compress the code a lot with using mapcar etc and most if not all command functions can be replaced with vla functions. But this would save you a few micro seconds , hell maybe a whole second... big deal. if it works it works. It's 1 in the morning for me so I wont be doing any coding no more for a wile :sleeping:

Link to comment
Share on other sites

About the only saving is in your make layers can be done as say read file but you have so few is it worth it. There are other ways also make a list of ((layname1 col LT)(layname2 col lt)) and so on reading the list and making, 3rd use a make layer defun (laych "Background" 9 "Continuous), in my case this is a library function that checks if layer exists ignore else make it.

Link to comment
Share on other sites

  (initdia 0)
[color=red]  (setq filename "S:\\folder-1\\subfolder-1\\filename")[/color]
 (if (= 0 (getvar "SDI"))
   (command "-insert" [color=green]filename[/color] '(0. 0. 0.) "" "" ""))   ; Inserts Client Border   
 (while (= (logand (getvar "cmdactive")1)1) 
   (command ""))   
 (initdia) 
 (princ)  
 [color=red](setq filename (strcat"*" "S:\\folder-2\\subfolder-2\\filename"))[/color] 
 (if  (= 0 (getvar "SDI"))     
   (command "-insert" [color=green]filename[/color] '(36. 0. 0.) "" "" )) ; Inserts Company Border with standard annotation blocks 
 (while (= (logand (getvar "cmdactive")1)1)   
   (command ""))     
 (initdia) 
  (princ) )

The red items in your code are never used. I have subsituted the variable "filename" in the command insert calls. If you want to go with the hard coded file name string in the command insert calls, then the two red lines of code can be removed. If not then you can put it in a while loop

  (initdia 0)
[color=red] [color=black] (setq filenames (list (cons "S:\\folder-1\\subfolder-1\\filename" [/color][/color]'(0. 0. 0.)) 
                       (cons "*S:\\folder-2\\subfolder-2\\filename" '(36. 0. 0.))
                 ))
[color=red] [color=black](foreach f_name filenames[/color][/color]
   (if (= 0 (getvar "SDI"))
     (command "-insert" (car f_name) (cadr f_name) "" "" "")
   )
   (while (= (logand (getvar "cmdactive")1)1) 
     (command "")
   )   
   (initdia) 
   (princ)
) 

Link to comment
Share on other sites

The red items in your code are never used. I have subsituted the variable "filename" in the command insert calls. If you want to go with the hard coded file name string in the command insert calls, then the two red lines of code can be removed. If not then you can put it in a while loop

 

 

correct but OP said his head was about to explode and it didn't effect the working of the code so left it at that (and it was late)

 

 

but you still give 3 times "" in the insert command and that's one to many for the filename with the * prefix. Maybe leave them out completely and let the while cmdactive take care of that?

 

 

Have a nice weekend.

 

 

gr. Rlx

Link to comment
Share on other sites

correct but OP said his head was about to explode and it didn't effect the working of the code so left it at that (and it was late)

 

 

but you still give 3 times "" in the insert command and that's one to many for the filename with the * prefix. Maybe leave them out completely and let the while cmdactive take care of that?

 

Have a nice weekend.

 

 

gr. Rlx

 

 

I need more sleep, I don't remember posting that.:sleeping:

Link to comment
Share on other sites

Dont forget blocks with attributes can effect -Insert a quicker way may be look at Lee-mac steal once loaded just copy what ever from another dwg such as a DWT. It can be command line driven so no user input required.

Link to comment
Share on other sites

Dont forget blocks with attributes can effect -Insert a quicker way may be look at Lee-mac steal once loaded just copy what ever from another dwg such as a DWT. It can be command line driven so no user input required.

 

 

I would probably set 'attreq to 0 instead of 1 and also variable 'expert to make sure redefine isn't a problem but you don't learn from stealing someone elses program ;-)

Link to comment
Share on other sites

Sorry for the delayed response, I have been out of the office since Thursday. I thank you all for your help and input. As I am trying to learn and become proficient in this I am compiling a list of helps and notes as reference. I've already looked at the tutorials from lee-mac and found some other sources to reference as well but I am more of a hands on type. Thanks again :D

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