Author Topic: Dimensioning objects from selection set - Stumped!  (Read 1486 times)

0 Members and 1 Guest are viewing this topic.

QuicklyCAD

  • Mosquito
  • Posts: 3
Dimensioning objects from selection set - Stumped!
« on: September 30, 2020, 10:02:23 PM »
Hi all,
I've benefited tons from the site in the past, but this is my first post.  I'm in need of some assistance in solving a LISP puzzle that has been driving me crazy.
I created a simple routine that gathers objects (lines and arcs) into a selection set and then adds dimensions to the objects.  This routine worked perfectly when I wrote it, but in the days since it has stopped working consistently and I have exhausted my knowledge in trying to figure out why.  It now fails at the point where the dimension command attempts to select the object in the SS.  Occasionally it will proceed through the routine successfully but the majority of the time it now fails. If anyone has any insight I would greatly appreciate it!  Code inserted below.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:sds (/ ss i obj vlObj ent pt dObj)
  2.   (princ "\nSelect Boundaries: ")
  3.   (setq ss (ssget '((8 . "PP - Boundary")))
  4.         i 0)
  5.   (repeat (sslength ss)
  6.     (setq obj (ssname ss i)
  7.           vlObj (vlax-ename->vla-object obj)
  8.           ent (entget obj))
  9.     (cond
  10.       ((= (cdr (assoc 0 ent)) "LINE")
  11.        (setq pt (cdr (assoc 10 ent)))
  12.        (command "dimaligned" "" obj pt))
  13.       ((= (cdr (assoc 0 ent)) "ARC")
  14.        (command "dimarc" obj pt))
  15.       );cond
  16.        (setq dObj (vlax-ename->vla-object (entlast)))
  17.        (vlax-put-property dObj 'Layer "PP - Dims - Site")
  18.        (vlax-put-property dObj 'StyleName "Site Dims")
  19.     (setq i (+ i 1))
  20.     );repeat
  21.   )
  22.  

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimensioning objects from selection set - Stumped!
« Reply #1 on: October 01, 2020, 03:59:46 AM »
This could be a speed problem, you are accessing entlast immediately after the instruction to create it. Does the problem still occur if you cut out the entlast like this?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:sds (/ doc spc ss cnt ent el spt ept mpt nobj)
  2.         spc (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
  3.   )
  4.   (princ "\nSelect Boundaries: ")
  5.   (setq ss (ssget '((8 . "PP - Boundary"))))
  6.   (cond (ss
  7.           (repeat (setq cnt (sslength ss))
  8.             (setq ent (ssname ss (setq cnt (1- cnt)))
  9.                   el (entget ent)
  10.                   spt (vlax-curve-getstartpoint ent)
  11.                   ept (vlax-curve-getendpoint ent)
  12.                   mpt (vlax-curve-getpointatdist ent (/ (vlax-curve-getdistatpoint ent ept) 2.0))
  13.             );end_setq
  14.             (cond ( (= (cdr (assoc 0 el)) "LINE") (setq nobj (vlax-invoke spc 'adddimaligned spt ept mpt)))
  15.                   ( (= (cdr (assoc 0 el)) "ARC") (setq nobj (vlax-invoke spc 'adddimarc (cdr (assoc 10 el)) spt ept mpt)))
  16.             );end_cond
  17.             (mapcar '(lambda (x y) (vlax-put-property nobj x y)) (list 'layer 'stylename) (list "PP - Dims - Site" "Site Dims"))
  18.           );end_repeat
  19.         )
  20.   );end_cond
  21. )
  22.  

QuicklyCAD

  • Mosquito
  • Posts: 3
Re: Dimensioning objects from selection set - Stumped!
« Reply #2 on: October 01, 2020, 05:23:47 AM »
Thanks Dlanor  :lol:
First off, your code seems to work like a charm!  Thank you very much for the quick response, that was driving me crazy.

In regards to your comment, the issue I was facing wasn't due to speed as, in order to troubleshoot, I copied bits of the code out and even just starting the dimension would fail with the method I was using.  I think it boils down to the method of object creation: I was operating from a clunky 'command line' approach while your routine, correctly, utilizes the vlax functions.

Thanks again - I will be utilizing the routine and learning a significant amount from your code!  :nerdystraight:

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dimensioning objects from selection set - Stumped!
« Reply #3 on: October 01, 2020, 07:25:18 AM »
Glad I could Help :-)

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Dimensioning objects from selection set - Stumped!
« Reply #4 on: October 01, 2020, 09:53:06 PM »
Any reason why you would not just set correct layer and dim style at start of code, reset if required at end, then no change properties. Can check also does exist ?
A man who never made a mistake never made anything

d2010

  • Bull Frog
  • Posts: 323
Re: Dimensioning objects from selection set - Stumped!
« Reply #5 on: October 02, 2020, 01:18:12 PM »
How do I set Windows PIN access to myLisp? 1978=pp_linedimarcdim_jspin15.lsp
I compile your-programe to three-mode(Normal,Debug=dup35 and PinAcces). You must   scan for allLayer/s with Line+Arcs;with, at means  you execute (ssget "x") inside each-Layer.:whistling:
Code - Auto/Visual Lisp: [Select]
  1.  (setq nobj (vlax-for lay layer.dll (setq;|a16889|;
  2.          nam (vla-get-name lay)
  3.          imn (if (and  (=  (vla-get-layeron lay) vlax_true) (=  (vla-get-freeze lay) vlax_false)) 1 0)
  4.          s3m (if (=  imn 1) (ssget "X" (list (cons 0 "LINE,ARC,CIRCLE") (cons 8 nam) cow)) s3m)
  5.          bor (if (and (=  imn 1) (/= s3m nil)) (sslength s3m) (- 100))
  6.          mli (if (>  bor 0) (cons nam mli) mli)
  7.  
    • The setmypid is global variabile name inside.lsp. Idem for getmypid.
    • (pp_linedimarcdim_jsdup35.lsp "When you got error , You type (princ setmypid) at line-command")
  • I build menu like table with --------------------
:wideeyed:
. Can check also does exist ?
:uglystupid2:
Code: [Select]
Give NameLayer fromLayerId*
*00:e-powr-devc-neww----------------[2 *00]
*01:e-powr-circ-dash-neww-----------[2 *01]
*02:e-powr-circ-neww----------------[60 *02]
*03:e-powr-circ-exst----------------[14 *03]
*04:e-powr-panl-exst----------------[2 *04]
Eg. 02[enter] for 60x(Lines+Arcs) and *03=LayerId you enter at line-command. with )(getint)
« Last Edit: October 04, 2020, 01:27:18 AM by d2010 »

QuicklyCAD

  • Mosquito
  • Posts: 3
Re: Dimensioning objects from selection set - Stumped!
« Reply #6 on: October 02, 2020, 01:48:36 PM »
Any reason why you would not just set correct layer and dim style at start of code, reset if required at end, then no change properties. Can check also does exist ?

Setting the layer at the start is a good idea, would simplify the execution.  I guess I got tunnel vision working on this one because that is what I have done in other similar scenarios.  Checking if it exists is also a good idea but not needed in my current application as the layers will already be present 100% of the time.  Thanks for the input!

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Dimensioning objects from selection set - Stumped!
« Reply #7 on: October 02, 2020, 07:53:38 PM »
No worries make it a library routine to check, then its like 1 line in your code.

(chklay "dims3" 3 "Continous")
A man who never made a mistake never made anything