Author Topic: dimscale in dxf code?  (Read 3174 times)

0 Members and 1 Guest are viewing this topic.

paulmcz

  • Bull Frog
  • Posts: 202
dimscale in dxf code?
« on: June 27, 2006, 04:29:51 PM »
I'd like to select dimension and set the dimscale to the value that dimension has. Where in the dxf code can I find the value and how can I retrieve it, if the dimscale for that dimension was set to 1?
This is what I have but it doesn't work if the selected dimension has dimscale 1.

Code: [Select]
(defun c:dsc (/ dim lst xd)
(setq dim (car (entsel "\n Select dimension to copy dimscale from: ")))
(setq lst (entget dim '("ACAD")))
(setq xd (cdr (assoc 1040 (cdadr (assoc -3 lst)))))
(setvar "dimscale" xd)
)

Thanks,
Paul.

Crank

  • Water Moccasin
  • Posts: 1503
Re: dimscale in dxf code?
« Reply #1 on: June 27, 2006, 05:27:18 PM »
Code: [Select]
(command ".dim1" "restore" "" pause)
Vault Professional 2023     +     AEC Collection

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: dimscale in dxf code?
« Reply #2 on: June 27, 2006, 05:42:35 PM »
Code: [Select]
(or (setq xd (cdr (assoc 1040 (cdadr (assoc -3 lst)))))
    (setq xd 1.0)
    )
This will default to 1 if the selected dimension has not been altered.

A comment if I may: You should verify that 1.) the user DID select something, and 2.) the selected entity IS a dimension.....

paulmcz

  • Bull Frog
  • Posts: 202
Re: dimscale in dxf code?
« Reply #3 on: June 27, 2006, 08:11:28 PM »
Code: [Select]
(or (setq xd (cdr (assoc 1040 (cdadr (assoc -3 lst)))))
    (setq xd 1.0)
    )
This will default to 1 if the selected dimension has not been altered.

A comment if I may: You should verify that 1.) the user DID select something, and 2.) the selected entity IS a dimension.....

Thanks Jeff. That's what I have.

Code: [Select]
(defun c:dsc (/ dim lst xd)
  (command "cmdecho" (getvar "cmdecho"))
  (setq
    dim (car (entsel "\n Select dimension to copy dimscale from: "))
  )
  (setq lst (entget dim '("ACAD")))
  (cond ((or
   (= (cdr (assoc 0 lst)) "DIMENSION")
   (= (cdr (assoc 0 lst)) "LEADER")
)
(if (assoc -3 lst)
    (setq xd (cdr (assoc 1040 (cdadr (assoc -3 lst)))))
    (setq xd 1.0)
  )
   (setvar "dimscale" xd)
   (princ (strcat "\n Dimscale is now set to: " (rtos xd 2 3)))

)
(T (princ "\n No dimension selected"))
  )
  (princ)
)

I am wondering if the dimscale value exists in the code if you select dimension that has dimscale 1. This > (assoc -3 lst) < evaluates to nil in such case.

paulmcz

  • Bull Frog
  • Posts: 202
Re: dimscale in dxf code?
« Reply #4 on: June 27, 2006, 08:21:36 PM »
Code: [Select]
(command ".dim1" "restore" "" pause)

Very simple and it does the job too.
Thanks.

Nick-LTC

  • Guest
Re: dimscale in dxf code?
« Reply #5 on: July 06, 2006, 12:07:18 PM »
;try this, in your cond statement

(cond   ((or
      (= (cdr (assoc 0 lst)) "DIMENSION")
      (= (cdr (assoc 0 lst)) "LEADER")
   )
   (if (assoc -3 lst)
       (setq xd (if (setq xd (cdr (assoc 1040 (cdadr (assoc -3 lst))))) xd 1.0)); added to check for nil<<<<<<<<<<<
       (setq xd 1.0)
     )
      (setvar "dimscale" xd)
      (princ (strcat "\n Dimscale is now set to: " (rtos xd 2 3)))
   
   )
   (T (princ "\n No dimension selected"))
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: dimscale in dxf code?
« Reply #6 on: July 06, 2006, 12:33:12 PM »
Nick, welcome to the swamp.

Here is my version of paulmcz's routine.

Code: [Select]
(defun c:dsc (/ dim lst xd usercmd)
  (setq usercmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (or
    (and
      (setq dim (entsel "\n Select dimension to copy dimscale from: "))
      (setq lst (entget (car dim) '("ACAD")))
      (vl-position (cdr (assoc 0 lst)) '("DIMENSION" "LEADER"))
      (or
        (and (assoc -3 lst)
             (setq xd (cdr (assoc 1040 (cdadr (assoc -3 lst)))))
        )
        (setq xd 1.0)
      )
      (setvar "dimscale" xd)
      (princ (strcat "\n Dimscale is now set to: " (rtos xd 2 3)))
    )
    (princ "\n No dimension selected")
  )
  (setvar "cmdecho" usercmd)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.