VLA SSGET
I'm handling something wrong here. I'm trying to avoid user input by selecting the lower left hand corner of the border at 0,0 with a crossing window.It acts like it runs but I get no printed result and the dimscale isn't updated. I'm clearly doing something wrong with my (while (ssget statement. Am I'm even approaching it right? Do I need to use
I've tried other variations and did get a selection set established but with it I got "bad point argument" errors.
(defun c:TB_Dim (/ dim x len scale)
(setq dim (getvar 'dimscale))
(while (setq y (ssget "c" '(1 1) '(-1 -1))))
(if (setq x (vlax-ename->vla-object y)) ;;(car (entsel "\nSelect Polyline: "))))
(progn
(vla-getboundingbox x 'minpt 'maxpt)
(setq LL (vlax-safearray->list minpt)
UR (vlax-safearray->list maxpt)
L&W (mapcar '- UR LL)
)
(prompt (strcat "\nSegment length: " (rtos (car L&W) 2 4)))
(setq scale (/ (car L&W) 34))
(if (equal dim scale 0.0001)
(prompt (strcat "\nDimscale is Correct: " (rtos dim 2 4)))
(progn
(prompt (strcat "\nDimscale Changing from [" (rtos dim 2 4) "] to " (rtos scale 2 4)))
(setvar 'dimscale scale)
)
)
)
(prompt "\nNothing Selected try again")
)
)
(princ)
)
Do I need an approach like this?
;; Active Document:
> (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
>
> (if (ssget "x" )
>
> (progn
>
> (setq ss (vla-get-ActiveSelectionSet doc))
>
> ;; Now ss contains the same objects found
> ;; by the call to (ssget)
>
> ;; after you're done, you can release it:
>
> (vlax-release-object ss)
> )
> )
> Perhaps consider the following code:
(defun c:tb_dim ( / box dim idx mni mxa obj scl sel )
(if (setq sel (ssget "_C" '(1 1) '(-1 -1)))
(progn
(setq dim (getvar 'dimscale))
(repeat (setq idx (sslength sel))
(setq idx (1- idx)
obj (vlax-ename->vla-object (ssname sel idx))
)
(vla-getboundingbox obj 'mni 'mxa)
(setq box (mapcar '- (vlax-safearray->list mxa) (vlax-safearray->list mni))
scl (/ (car box) 34.0)
)
(prompt (strcat "\nSegment Length: " (rtos (car box) 2 4)))
(if (equal scl dim 1e-4)
(prompt (strcat "\nDimscale is correct: " (rtos dim 2 4)))
(progn
(prompt (strcat "\nDimscale changing from [" (rtos dim 2 4) "] to " (rtos scl 2 4)))
(setvar 'dimscale scl)
)
)
)
)
(prompt "\nNothing selected, try again.")
)
(princ)
)
(vl-load-com) (princ)
A few points to note:
Objects must be visible within the drawing area in order to be selected by the ssget function when a graphical selection method is used
This uses a repeat loop to iterate over the set - you may wish to consider only operating on the first object in the set, given the operations performed by the function If you're only interested in one object, you can omit the index variable altogether - hence the code may become:
(defun c:tb_dim ( / box dim mni mxa obj scl sel )
(if (setq sel (ssget "_C" '(1 1) '(-1 -1)))
(progn
(setq dim (getvar 'dimscale)
obj (vlax-ename->vla-object (ssname sel 0))
)
(vla-getboundingbox obj 'mni 'mxa)
(setq box (mapcar '- (vlax-safearray->list mxa) (vlax-safearray->list mni))
scl (/ (car box) 34.0)
)
(prompt (strcat "\nSegment Length: " (rtos (car box) 2 4)))
(if (equal scl dim 1e-4)
(prompt (strcat "\nDimscale is correct: " (rtos dim 2 4)))
(progn
(prompt (strcat "\nDimscale changing from [" (rtos dim 2 4) "] to " (rtos scl 2 4)))
(setvar 'dimscale scl)
)
)
)
(prompt "\nNothing selected, try again.")
)
(princ)
)
(vl-load-com) (princ) I swear to got I tried that!!! Musta not been squinting just right.
Thanks Lee.
Tried to combine this piece of code with another piece of code so they run from the same Defun.
It all works but I'm getting this as a return result.
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Segment Length: 272.0000
Dimscale is correct: 8.0000
Error: Function cancelledSpecify height of text or : *Cancel*
Unless I escape, it could run for days. But you get the idea.
;;; Sets dimscale based on length of Bottom or Top white border line.
;;; TB_DIM at command line
;;; ---------------------------------------------------------------------------------
;;; Created 07/05/22 by Jerry Logan
;;; Assist from MHupp/Lee Mac in The Swamp
;;;Routine selects bottom white border line, checks it's length and sets
;;;Dimscale equal to that length by dividing bottom line by 34.
;;;Refer to OneNote - Drawing Conversion Help folder "Conversion Help" page
;;;DIMSCALE/BORDER SIZE CHART for correct dimscales.
;;; ---------------------------------------------------------------------------------
(defun tb_dim ( / box dimsc idx mni mxa obj scl sel )
(if (setq sel (ssget "_C" '(1 1) '(-1 -1)))
(progn
(setq dimsc (getvar 'dimscale)
obj (vlax-ename->vla-object (ssname sel 0))
)
(vla-getboundingbox obj 'mni 'mxa)
(setq box (mapcar '- (vlax-safearray->list mxa) (vlax-safearray->list mni))
scl (/ (car box) 34.0)
)
(prompt (strcat "\nSegment Length: " (rtos (car box) 2 4)))
(if (equal scl dimsc 1e-4)
(prompt (strcat "\nDimscale is correct: " (rtos dimsc 2 4)))
(progn
(prompt (strcat "\nDimscale changing from [" (rtos dimsc 2 4) "] to " (rtos scl 2 4)))
(setvar 'dimscale scl)
)
)
)
(prompt "\nNothing selected, try again.")
)
(princ)
)
(vl-load-com) (princ)
;;; -----------------------------------------------------
(defun Sctxt ( / dimsc )
(setq dimsc (getvar "dimscale"))
(setvar "CMDECHO" 0)
(setvar "BLIPMODE" 0)
(command ".style" "Standard" "ipco.shx" (* 1.000 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L080" "ipco.shx" (* 0.0781 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L100" "ipco.shx" (* 0.0938 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L120" "ipco.shx" (* 0.1094 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L140" "ipco.shx" (* 0.1406 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L175" "ipco.shx" (* 0.1563 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L200" "ipco.shx" (* 0.1719 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "L240" "ipco.shx" (* 0.2187 dimsc) "0.85" "0" "n" "n" "n")
(command ".style" "LS080" "ipco.shx" (* 0.0781 dimsc) "0.85" "20" "n" "n" "n")
(command ".style" "LS100" "ipco.shx" (* 0.0938 dimsc) "0.85" "20" "n" "n" "n")
(command ".style" "LS120" "ipco.shx" (* 0.1094 dimsc) "0.85" "20" "n" "n" "n")
(command ".style" "LS140" "ipco.shx" (* 0.1406 dimsc) "0.85" "20" "n" "n" "n")
(command ".style" "LS175" "ipco.shx" (* 0.1563 dimsc) "0.85" "20" "n" "n" "n")
(command ".style" "LS200" "ipco.shx" (* 0.1719 dimsc) "0.85" "20" "n" "n" "n")
(command ".style" "LS240" "ipco.shx" (* 0.2187 dimsc) "0.85" "20" "n" "n" "n")
(princ)
)
(defun c:Txt_Dim ()
(while
(tb_dim)
(sctxt)
)
)
It's because you are running the functions in a while loop. Remove (while ) and it should work.
(defun c:Txt_Dim ()
(while
(tb_dim)
(sctxt)
)
) Thanks Ron.
页:
[1]