+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Senior Member bsamc2000's Avatar
    Computer Details
    bsamc2000's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Z400
    CPU:
    Intel Xeon 2.66GHz
    Graphics:
    NVIDIA GeForce 9500 GT
    Monitor:
    E228WFP (2x)
    Using
    AutoCAD 2011
    Join Date
    Mar 2007
    Location
    Columbus, Ohio
    Posts
    120

    Question Following a path

    Registered forum members do not see this ad.

    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
    Attached Images

  2. #2
    Forum Deity
    Using
    Civil 3D 2008
    Join Date
    Sep 2006
    Location
    Pittsburgh, PA, USA
    Posts
    3,581

    Default

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

  3. #3
    Senior Member bsamc2000's Avatar
    Computer Details
    bsamc2000's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Z400
    CPU:
    Intel Xeon 2.66GHz
    Graphics:
    NVIDIA GeForce 9500 GT
    Monitor:
    E228WFP (2x)
    Using
    AutoCAD 2011
    Join Date
    Mar 2007
    Location
    Columbus, Ohio
    Posts
    120

    Default

    Quote Originally Posted by lpseifert View Post
    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

  4. #4
    Senior Member
    Using
    not applicable
    Join Date
    May 2007
    Posts
    126

    Default

    Quote Originally Posted by bsamc2000 View Post
    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.

  5. #5
    Super Member
    Using
    AutoCAD 2007
    Join Date
    Aug 2003
    Location
    Livingston, Scotland
    Posts
    995

    Default

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

    btw, vlax-curve-* is not only for arcs
    ResourceCAD.... the Resource for your CAD Solutions

  6. #6
    Junior Member
    Using
    AutoCAD 2002
    Join Date
    Oct 2007
    Location
    Nhatrang, Vietnam
    Posts
    10

    Default

    Quote Originally Posted by bsamc2000 View Post
    ... 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)?

  7. #7
    Senior Member bsamc2000's Avatar
    Computer Details
    bsamc2000's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Z400
    CPU:
    Intel Xeon 2.66GHz
    Graphics:
    NVIDIA GeForce 9500 GT
    Monitor:
    E228WFP (2x)
    Using
    AutoCAD 2011
    Join Date
    Mar 2007
    Location
    Columbus, Ohio
    Posts
    120

    Question

    Quote Originally Posted by VovKa View Post
    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)

    Quote Originally Posted by hendie View Post
    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
    Attached Files

  8. #8
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    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).

  9. #9
    Senior Member
    Using
    not applicable
    Join Date
    May 2007
    Posts
    126

    Default

    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
    Code:
    (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)
    )

  10. #10
    Junior Member
    Using
    AutoCAD 2002
    Join Date
    Oct 2007
    Location
    Nhatrang, Vietnam
    Posts
    10

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by CarlB View Post
    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:
    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

Similar Threads

  1. sun path
    By wikkee in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 3rd Oct 2011, 02:16 pm
  2. camera path
    By bop in forum AutoCAD 3D Modelling & Rendering
    Replies: 6
    Last Post: 3rd Aug 2007, 05:01 pm
  3. What path?
    By Lazer in forum Autodesk Inventor
    Replies: 1
    Last Post: 1st Jul 2007, 01:55 pm
  4. BATCH CHANGE FULL PATH TO RELATIVE PATH
    By beth in forum AutoCAD General
    Replies: 3
    Last Post: 21st Jun 2006, 02:38 am
  5. Array with path
    By Jose in forum AutoCAD General
    Replies: 5
    Last Post: 21st Apr 2005, 02:51 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts