Jump to content

Recommended Posts

Posted

Someone please put me out of my misery! I have been fighting with this for the two days.

I am writing a program to do the following:

1.) Select a block

2.) Pick (2) location points

3.) Select a path

4.) Give a stepping distance

After this information is given I would like the program to step the block along a given path at the stepping distance.

I gave figured everything out with one exception. How do I calculate the transition between a straight line and an arc? My brain just put the formula down in the code. I know it is possible.

I’ve attached an image to help clarify. Position 3 is the area in question.

 

Thank you in advance,

Brian

Path.jpg

Posted

Seems like the Measure command would do what you want to accomplish.

Posted
Seems like the Measure command would do what you want to accomplish.

 

I would agree except that I would like to have the program step through the movements. I had a program that could do this, but I lost it and can not find a copy of the program. I was doing this back in version 12.

 

Thank you,

Brian

Posted
2.) Pick (2) location points

 

what are location points? those marked with red and blue? if so, "measure" command won't do exactly what you need.

Posted

look into the vlax-curve functions, that will give you what you need

 

btw, vlax-curve-* is not only for arcs

Posted
... I would like to have the program step through the movements...

 

Thank you,

Brian

 

That’s very difficult in general cases. But if you limit it in some specific conditions (form and dimensions of curve), I think we can solve it.

Could you post your drawing file with full elements (curve and block)?

Posted
what are location points? those marked with red and blue? if so, "measure" command won't do exactly what you need.

The red and blue points must stay in contact with the path at all times. They represent trolleys on a conveyor and are a fixed distance apart. (200.0mm)

 

look into the vlax-curve functions, that will give you what you need

 

btw, vlax-curve-* is not only for arcs

I will check into the vlax-curve function. I have not used them before.

 

I have attached a copy of the example. I hope this helps. I will post a copy of the program later today after I clean it up a bit.

 

Thank you,

Brian

Path.dwg

Posted

I believe trying to calculate the point through a transition would be a a nightmare. And what iff line isn't tangent to the arc, or path is a spline, or....

 

So I propose using a method similar to doing it manually. That would be to draw a circle at the front of the trolley, R=200, and where it intersects the tracks is the back of the trolley. The routine would place a circle, determine the 2 intersections of the track with the function "vla-intersectwith". This will give you one or 2 points of intersection. If 2 points, find the one neast the beginning along the curve (one of the vlax-curve functions).

Posted

try it with "Path.dwg"

takes block insertion point as "location point 1"

it's rather slow, a little bit inaccurate (depends on Fuzz varible), no error catching

(vl-load-com)
(defun test (/
     Dist
     EndDist
     EndPoint
     Fuzz
     LineLength
     BlockObj
     PathObj
     StartPoint
     Step
     Point1
     Point2
     MSpaceObj
    )
 (setq MSpaceObj (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))))
 (princ "\nSelect BLOCK: ")
 (setq	BlockObj   (vlax-ename->vla-object (car (entsel)))
Point1	   (vlax-safearray->list
	     (vlax-variant-value (vla-get-InsertionPoint BlockObj))
	   )
Point2	   (getpoint Point1 "\nPick location point 2: ")
LineLength (distance Point1 Point2)
 )
 (princ "\nSelect PATH: ")
 (setq PathObj (vlax-ename->vla-object (car (entsel))))
 (setq EndDist (vlax-curve-getDistAtParam PathObj (vlax-curve-getEndParam PathObj)))
 (setq	Step (getreal "\nEnter stepping distance: ")
Fuzz 0.01
Dist 0.0
 )
 (while (< Dist EndDist)
   (setq StartPoint (vlax-curve-getPointAtDist PathObj Dist))
   (while (and	(< (setq Dist (+ Dist Fuzz)) EndDist)
	(< (distance StartPoint
		     (setq EndPoint (vlax-curve-getPointAtDist PathObj Dist))
	   )
	   LineLength
	)
   )
   )
   (if	(< Dist EndDist)
     (progn (vla-InsertBlock
       MSpaceObj
       (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 2)) StartPoint))
       (vla-Get-Name BlockObj)
       1.0
       1.0
       1.0
       (angle StartPoint EndPoint)
     )
     (setq Dist (+ Dist Step))
     )
   )
 )
 (vlax-release-object PathObj)
 (vlax-release-object BlockObj)
 (vlax-release-object MSpaceObj)
 (princ)
)

Posted
I believe trying to calculate the point through a transition would be a a nightmare. And what iff line isn't tangent to the arc, or path is a spline, or....

 

So I propose using a method similar to doing it manually. That would be to draw a circle at the front of the trolley, R=200, and where it intersects the tracks is the back of the trolley. The routine would place a circle, determine the 2 intersections of the track with the function "vla-intersectwith". This will give you one or 2 points of intersection. If 2 points, find the one neast the beginning along the curve (one of the vlax-curve functions).

 

I agree with CarlB. That isn't expert method but give exact results.

This is code:

;;;===========================================
;;;Move objects along curve path
;;;Written by ssg - October 25th, 2007
;;;===========================================

;;;-------------------------------------------------------------------------------
(defun rtd(x) (/ (* x 180) pi) ) ;;;Change radian to degree
;;;-------------------------------------------------------------------------------
(defun Collect(e / ent2 SS1 SS2) ;;;Selection set from e to entlast
(setq SS1 (ssadd))
(ssadd e SS1)
(while (setq ent2 (entnext e)) 
   (ssadd ent2 SS1)
   (setq e ent2)
)
(setq SS2 SS1)
)
;;;-------------------------------------------------------------------------------
(defun Collect1(e / ss)
;;;Selection set after e to entlast. If e nil, select from fist entity of drawing.
(if (= e nil) (setq ss (collect (entnext)))
   (progn (setq ss (collect e)) (ssdel e ss))
)
)
;;;-------------------------------------------------------------------------------
(defun ints (e1 e2 / ob1 ob2 V L1 L2)
;;;Get intersections of e1, e2. Return LIST of points
(setq
   ob1 (vlax-ename->vla-object e1)
   ob2 (vlax-ename->vla-object e2)
)
(setq V (vlax-variant-value (vla-IntersectWith ob1 ob2 acExtendNone)))
(if (/= (vlax-safearray-get-u-bound V 1) -1)
   (progn
         (setq L1 (vlax-safearray->list V) L2 nil)
         (while L1
(setq L2 (append L2 (list (list (car L1) (cadr L1) (caddr L1)))))
(repeat 3 (setq L1 (cdr L1)))
         )
   )
   (setq L2 nil)
)
L2
)
;;;------------------------------------------------------------------------------
(defun getnearP (p p1 p2) ;;;Get nearer point by p. Return p1 or p2
(if (<= (distance p p1) (distance p p2)) p1 p2)
)
;;;------------------------------------------------------------------------------
(defun getpL(e st / el ss i et p pL)
;;;Get list of points by measure command, specified by curve e and step st
(setq el (entlast))
(command "measure" e st )
(setq ss (collect1 el) i 0)
(repeat (sslength ss) 
   (setq
       et (ssname ss i)
       p (cdr (assoc 10 (entget et)))
       pL (append pL (list p))
       i (1+ i)
   )
)
(command "erase" ss "")
pL
)
;;;------------------------------------------------------------------------------
(defun MoveStep()
(repeat (length pL)
   (setq p3 (nth j pL))
   (setq pa3 (vlax-curve-getParamAtPoint cur p3))
   (if (>= (* flag pa3) (* flag pa1))
       (progn
           (command "circle" p3 r) 
           (setq ipL (ints cur (entlast)))
           (if (> (length ipL) 1)
               (setq p4 (getnearP p1 (car ipL) (cadr ipL)))
               (setq p4 (car ipL))
           )
           (command "erase" (entlast) "")
           (command "move" ob "" p1 p3)
           (command "rotate" ob "" p3 (rtd (- (angle p3 p4) ag)))
           (setq p1 p3 ag (angle p3 p4))
           (command "delay" 100)
       )
   )
   (setq j (1+ j))
)
)
;;;===================MAIN====================
(defun C:MST( / ob p1 p2 cur pa1 pa2 st pL r ag j flag oldos p3 pa3 ipL p4)
(vl-load-com)
(prompt "Select objects will be moved...")
(setq
   ob (ssget)
   p1 (getpoint "\nFirst point (front):")
   p2 (getpoint "\nSecond point (back):")
   cur (car (entsel "\nSelect path:"))
   pa1 (vlax-curve-getParamAtPoint cur p1)
   pa2 (vlax-curve-getParamAtPoint cur p2)
)
(if (not (and pa1 pa2)) (progn (alert "1 or 2 points not on the path!") (exit)))
(setq
   st (getreal "\nStep:")
   pL (getpL cur st)
   r (distance p1 p2)
   ag (angle p1 p2)
   j 0
)
(if (> pa2 pa1) (progn (setq pL (reverse pL)) (setq flag -1)) (setq flag 1))
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(MoveStep)
(setvar "osmode" oldos)
(princ)
)
;;;===========================================
;;;NOTE
;;;Path is any types: line, pline, polygon, spline, circle, arc
;;;Objects: allow to select many objects that are any types (not block only) and lying anywhere
;;;But "First point" and "Second point" must be on the path
;;;I have tested with many cases, didn't find errors
;;;Positions of objects on the path are exact diametrically!
;;;But I think maybe it don't run correctly with some extraordinary curves

Posted

I think I have done what you want using the intersection of a circle to find the two points it works currently on polylines.

access-drv.txt

  • 1 year later...
Posted

SSG i like the Lisp can you get it to leave a shadow as well or instead of the animation?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...