Author Topic: ssget dashed line  (Read 2618 times)

0 Members and 1 Guest are viewing this topic.

hmspe

  • Bull Frog
  • Posts: 362
ssget dashed line
« on: February 14, 2007, 12:06:40 AM »
I'm having a problem with an insertion routine for wire count symbols when inserting the symbol on a dashed line, arc, or lwpolyline.  The purpose of the routine is to insert the symbol at the midpoint of the line, and automatically align the symbol along the line.  I'm using

Code: [Select]
  (prompt "\nSelect insertion point...  ")
  (command "_insert" symbol "PS" d_scale "MID" pause d_scale d_scale pause)

to do the insertion, then calling

Code: [Select]
  (defun ssat (pnt dist)
    (ssget "c"
     (list (- (car pnt) dist) (- (cadr pnt) dist))
     (list (+ (car pnt) dist) (+ (cadr pnt) dist))
    )
  )

with a very small value for dist and pnt set to the insertion point of the symbol to get the line I'm inserting on.  If the midpoint of the line happens to fall on a gap between dashes the 'ssget "c"' doesn't find the line.

Any suggestions on how to (1) snag the line/arc/lwployline at the insert command, or (2) deal with the gaps at the ssget without opening up the crossing box so much that I get other entities selected? 

One other minor issue is overriding the "mid" osnap in the insert command for those times when there are interfering entities at the midpoint.  The first override (shift-right click/nearest) does not override, so I have to do a second override.  Any way to fix this?       

Thanks in advance.

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

Fatty

  • Guest
Re: ssget dashed line
« Reply #1 on: February 14, 2007, 07:08:49 AM »
Try this one but quick and dirty
Hth

Code: [Select]
(defun C:BW (/ ent obj pt)
(vl-load-com)
(setvar "cmdecho" 0)
(setq osm (getvar "osmode"))
(setvar "osmode" 2)
 
(while
(setq ent (entsel "\nSelect the wire (or hit Enter to exit): "))
(setq obj (vlax-ename->vla-object (car ent))) 
(setq pt (vlax-curve-getclosestpointto obj
   (vlax-curve-getpointatparam obj
     (/ (vlax-curve-getendparam obj) 2))));<-- force to get mid point
(setvar "osmode" 0)
(command "._-insert" "triang" pt 1 1 0)
(setvar "osmode" 512)
(command "._rotate" "_L" "" pt pause)
(setvar "osmode" 2)
)
(setvar "cmdecho" 1)
(setvar "osmode" 0) 
(princ)
)
(princ "\n\t\t* Type BW to execute *")
(princ)

~'J'~

hmspe

  • Bull Frog
  • Posts: 362
Re: ssget dashed line
« Reply #2 on: February 14, 2007, 08:55:29 AM »
Try this one but quick and dirty

Thanks for the suggestion. 

The guys in my office say it's very important for this routine to be like "drag and drop" -- they want to be able to see the symbol and the symbol's rotation while they are selecting the line to insert the symbol on, so they can visualize how the symbol will look.  If there's a lot of other line work near the midpoint of the line they need to move the symbol so it's readily visible.  I probably should have included this requirement in my original post but I was trying to keep the size of the post as small as possible.

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

VVA

  • Newt
  • Posts: 166
Re: ssget dashed line
« Reply #3 on: February 14, 2007, 11:49:51 AM »
Can somehow so
Change "triang" on your block name
Code: [Select]
(defun RTD (a)(/ (* a 180.0) pi))
(defun DTR (a)(* pi (/ a 180.0)))
(defun mip-error-save-sysvar (sysvar-list)
  (foreach item  sysvar-list
    (setq *mip-sysvar-list*
     (cons (list (car item) (getvar (car item))) *mip-sysvar-list*))
    (if  (cadr item)(setvar (car item) (cadr item))) ;_ end of if
    ) ;_ end of foreach
  ) ;_ end of defun
(defun mip-error-restore-sysvar ()
  (if *mip-sysvar-list*
    (foreach item *mip-sysvar-list* (setvar (car item) (cadr item))))
  (setq *mip-sysvar-list* nil)(gc)) ;_ end of defun
(defun C:BW (/ ent obj pt *error* ang ug pt1 e1 ugt1 ugt2)
 (defun *error* (msg)
 (princ msg)
(while (> (getvar "CMDACTIVE") 0)(command)) 
  (mapcar '(lambda ( item)
      (cond
((and (= (type item) 'ENAME)(entget item))(entdel item))
((and (= (type item) 'VLA-OBJECT) (vlax-read-enabled-p item))
(vl-catch-all-apply 'vla-Delete (list item)))
(t nil)
)
      )
  *MIP-DELETE-ITEM*
    )
  (setq *MIP-DELETE-ITEM* nil)
  (mip-error-restore-sysvar)
  (princ)
  )
(vl-load-com)
(mip-error-save-sysvar
      (list
'("osmode")
'("SNAPANG")
'("ORTHOMODE")
'("CLAYER")
        '("CMDECHO" 0)
        '("limcheck"  0)
'("ANGBASE" 0)
'("ANGDIR" 0)
'("ATTDIA" 0)
'("ATTREQ" 0)
      )
      ) 
(while (setq ent (entsel "\nSelect the wire (or hit Enter to exit): "))
(setq obj (vlax-ename->vla-object (car ent))) 
(setq pt (vlax-curve-getclosestpointto obj (cadr ent))
     ang (vlax-curve-getFirstDeriv obj (vlax-curve-getParamAtPoint obj pt))
     pt1 (list (+ (car pt) (car ang)) (+ (cadr pt) (cadr ang)))
      pt (trans pt 0 1)
     pt1 (trans pt1 0 1)
     ang (angle pt pt1)
      ug (rtd ang))
(if (and (> ug 90.0) (<= ug 270.0))
(progn
 (setq ang (+ ang PI))
 (setq ug (rtd ang))
) ;_ end of progn
) ;_ end of if
(command "._-insert"
"triang" ;_<<=== Your block name
"_none"
"0,0"
1
1
ug)
  (setq e1 (entlast))
  (setq pt (cdr(assoc 10 (entget e1))))
  (setvar "LASTPOINT" pt)
  (setq *MIP-DELETE-ITEM* (append *MIP-DELETE-ITEM* (list e1)))
  (setvar "SNAPANG" (dtr ug))(setvar "ORTHOMODE" 1)
  (princ "\n Pick insertion point <exit>:")
  (setq ugt1 (cdr(assoc 50 (entget e1))))
  (command "_.CHANGE" e1 "" "" pause)
  (setq pt1 (getvar "LASTPOINT"))
  (if (equal pt pt1 0.000001)
(progn
  (while (> (getvar "CMDACTIVE") 0)(command ""))
  (entdel e1)
                  (setq *MIP-DELETE-ITEM* (vl-remove e1 *MIP-DELETE-ITEM*))
  )
  (progn
      (princ "\t Rotate angle <don't rotate>:")
      (command pause "")
                   (setq ugt2 (cdr(assoc 50 (entget e1))))
      (setvar "SNAPANG" 0)(setvar "ORTHOMODE" 0)
      (if (/= ugt1 ugt2)
(progn
(princ "\nNew insertion point <don't change>:")
(command "_.CHANGE" e1 "" "" pause "")
)
)
      (setq *MIP-DELETE-ITEM* (vl-remove e1 *MIP-DELETE-ITEM*))
  )
)
)
(mip-error-restore-sysvar)
  (princ)
  )
« Last Edit: February 14, 2007, 11:53:48 AM by VVA »