perpendicular Block insert at distance from starting point on a pline

perpendicular Block insert at distance from starting point on a pline

Anonymous
Not applicable
801 Views
6 Replies
Message 1 of 7

perpendicular Block insert at distance from starting point on a pline

Anonymous
Not applicable

Hi Guys and h Gurus,

i have really need of your help improoving and now let my code work

in my daily jobs i have to take hand measurement  on cloth and report on plines  inserting a perpendicular block that can be read from my converter

i know the existance of PUT.lsp but is not exactly what i want, and no learning by copy paste 

 

that is my starting code:

i think a obj ename conversion error on (setq pt2... line 

still studing lisp please have mercy

 

 

 

(defun C:block_from_distance (/ plsel p1 p2 cumdist  nextdist pt2 pt1 pt );(vl-load-com)); if needed
 (if (setq plsel (entsel "\nSelect Polyline: "))
   (progn
     (setq
       pl (car plsel)
       pt (osnap (getpoint "\nstarting point ") "_nea")
       cumdist (vlax-curve-getDistAtPoint pl pt)) ; setq
     ;(setvar 'osmode 0)
     (command "_.insert" "BLOCKNAME" pt "" "" "")
     (while
    (setq nextdist (getdist "\nDistance: "))
    (setq cumdist (+ cumdist nextdist))
    (setq pt1 (trans (vlax-curve-getPointAtDist pl cumdist) 1 0))
    (setq pt2 (vlax-curve-getClosestPointTo ( vlax-vla-object->ename ( vla-offset ( vlax-ename->vla-object ( plsel ) 2 ))) pt1 )  )
    (setq an ( getangle (pt1 pt2 )))
    (command "_.insert" "" (vlax-curve-getPointAtDist pl cumdist) "" "" an)
     )  ; while
   ) ; progn
 ); if
); defun
  

 

 

 

 

0 Likes
802 Views
6 Replies
Replies (6)
Message 2 of 7

john.uhden
Mentor
Mentor

I haven't checked out your code very well except to find one glaring error...

Change

(setq an ( getangle (pt1 pt2 )))
to
(setq an (angle pt1 pt2))

The getangle function takes user input.

John F. Uhden

0 Likes
Message 3 of 7

ВeekeeCZ
Consultant
Consultant

You should post a dwg test file. And always do.

Anyway, what I would do.

- pick a point on the polyline where block should be

- use nentselp to get polyline

- to get an angle using a derivation. (setq ang (angle '(0 0 0) (vlax-curve-getfirstderiv en (vlax-curve-getParamAtPoint en pt))))

- always use "_non" as osnap override prior to point supply within the command function. And call out the prompts as scale and rotation: (command "_.insert" "myblock" "_scale" 1 "_rot" 0 "_non" myPt)

- trans: make it work under WCS first., then entsel, getpoint, osnap, command are in UCS, vlax-curve-* in WCS.

- unless I am missing something, you would not need vla-offer, or even no vla-object...

Good luck

 
0 Likes
Message 4 of 7

Anonymous
Not applicable
maybe i have understood what did u think about that 


 

(defun C:tDCA (/ plsel cumdist  cumdist1 nextdist ang ang1 deg AAAA )
 (if (setq plsel (entsel "\nSelect Polyline: "))
   (progn
     (setq
       pl (car plsel)
       pt (osnap  (getpoint "\nSTARTING POINT ") "_nea")
       cumdist (vlax-curve-getDistAtPoint pl pt))
   
    (setq nextdist (GETREAL "INSERt"))
    (setq cumdist1 (+ cumdist nextdist))
    (SETQ AAAA (vlax-curve-getPointAtDist pl cumdist1))
     (setq ang (angle '(0 0 0) (vlax-curve-getfirstderiv pl (vlax-curve-getParamAtPoint pl AAAA ))))
     ;( setq ang1 (+ ang (/ pi 2)))
     (setq deg (atof (angtos ang 0 2)))
     (command "_.insert" "block" "_scale" 1 "_rot" deg "_non" AAAA )
   )
 )
)

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

like that?

(defun C:tDCA (/ plsel cumdist  cumdist1 nextdist ang ang1 deg AAAA )
 (if (setq plsel (entsel "\nSelect Polyline: "))
   (progn
     (setq
       pl (car plsel)
       pt (osnap  (getpoint "\nSTARTING POINT ") "_nea")
       cumdist (vlax-curve-getDistAtPoint pl pt))
   
    (setq nextdist (GETREAL "INSERt"))
    (setq cumdist1 (+ cumdist nextdist))
    (SETQ AAAA (vlax-curve-getPointAtDist pl cumdist1))
     (setq ang (angle '(0 0 0) (vlax-curve-getfirstderiv pl (vlax-curve-getParamAtPoint pl AAAA ))))
     ;( setq ang1 (+ ang (/ pi 2)))
     (setq deg (atof (angtos ang 0 2)))
     (command "_.insert" "block" "_scale" 1 "_rot" deg "_non" AAAA )
   )
 )
)
0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant

Yeah, something like it. It's good. Some thing might be little enhanced or shortened....

 

(vl-load-com)
(defun C:TDCA (/ plsel cumdist  cumdist1 nextdist ang ang1 deg AAAA )
 (if (and (setq pt (getpoint "\nSTARTING POINT: "))
	  (setq pl (car (nentselp pt)))
	  (setq nextdist (getdist pt "\nOFFSET DISTANCE: "))
	  (setq pt (vlax-curve-getClosestpointTo pl (trans pt 0 1)))
	  (setq cumdist (vlax-curve-getDistAtPoint pl pt))
	  (setq cumdist1 (+ cumdist nextdist))
	  (or (< cumdist1 (vlax-curve-getdistatparam pl (vlax-curve-getendparam pl)))
	      (prompt "\nError: You reached end of polyline!"))
	  (setq aaaa (vlax-curve-getpointatdist pl cumdist1))
	  (setq ang (angle '(0 0 0) (vlax-curve-getfirstderiv pl (vlax-curve-getParamAtPoint pl aaaa))))
	  )
   (command "_.insert" "block" "_scale" 1 "_rot" (angtos ang (getvar 'aunits) 8) "_non" (trans AAAA 0 1))
   )
  (princ)
)

 

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

One thing I don't see any accounting for is the direction the Polyline was drawn.  You can specify a point on it, and a distance along it from that point to set another point, but don't you need some control over which direction along it from the first point it should take to find the second point?  What you have will always proceed in the drawn direction along it, but can you be sure that will always give you the correct result?  [In my nearby city of Philadelphia, I could tell you, "Start at 401 North Broad Street and go half a mile from there," but if I don't say whether to go north or south, I can't control whether you will end up where I want you to.]  Or are yours drawn so that somehow you always know in which direction they progress?

 

Also, do you need a check on whether there is a point that much farther along the Polyline?  If that would put the second point past the end [or past the beginning, if something is worked out to determine the direction and it might be opposite to the drawn direction], it will cause an error.

Kent Cooper, AIA
0 Likes