Author Topic: How do I offset a point in my script?  (Read 1389 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
How do I offset a point in my script?
« on: February 21, 2017, 05:52:08 PM »
I wrote this script to insert a point a distance specified by the user. However, I would also like to include an offset distance. Thanks in advance.

Code: [Select]
(defun c:pp( / obj newlen plotpt pt)
  (princ "\nPlot point script will plot a point along a line or polyline.")
(setq ent (car (entsel "\n >> Select a line or polyline >>")))
(setq newlen 0)
(setq plotpt (getint "\nEnter a distance to plot a single point: "))
(setq newlen (+ plotpt newlen))
(setq pt (vlax-curve-getpointatdist ent newlen))
(entmakex (list
    (cons 0 "POINT")
    (cons 10 pt)
    (cons 8 "non-print")
    )
  )
  (princ "\Point created")
  )

*edited initial code because i saw some areas to clean up
« Last Edit: February 21, 2017, 07:16:34 PM by dubb »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I offset a point in my script?
« Reply #1 on: February 21, 2017, 06:14:47 PM »
And what is the offset amount relative to?
Would it be a set amount away from the new point & perpendicular to the vector the new point used?

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dubb

  • Swamp Rat
  • Posts: 1105
Re: How do I offset a point in my script?
« Reply #2 on: February 21, 2017, 06:32:31 PM »
And what is the offset amount relative to?
Would it be a set amount away from the new point & perpendicular to the vector the new point used?

Yes, the new point would be a user defined offset distance perpendicular from a point along a line.

dubb

  • Swamp Rat
  • Posts: 1105
Re: How do I offset a point in my script?
« Reply #3 on: February 21, 2017, 06:35:50 PM »
A screenshot might help

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How do I offset a point in my script?
« Reply #4 on: February 21, 2017, 06:41:49 PM »
Change:
Code: [Select]
(setq obj (vlax-ename->vla-object (car (entsel "\n >> Select a line or polyline >>"))))
To:
Code: [Select]
(setq ent (car (entsel "\n >> Select a line or polyline >>")))
And then use the following to obtain the direction of the tangent vector at the given point, and then add or subtract pi/2 radians to this angle:
Code: [Select]
(angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv ent (vlax-curve-getparamatpoint ent pt)) 0 ent t))

dubb

  • Swamp Rat
  • Posts: 1105
Re: How do I offset a point in my script?
« Reply #5 on: February 21, 2017, 08:19:17 PM »
Posting before I go home from the office. This is what I have so far. Thanks for the hints.
Code: [Select]
(defun c:pp( / newlen plotpt pt offset ang side)
  (princ "\nPlot point script will plot a point along a line or polyline.")
(setq ent (car (entsel "\n >> Select a line or polyline >>")))
(setq newlen 0)
(setq plotpt (getint "\nEnter a distance to plot a single point: "))
(setq offset (getint "\nEnter an offset distance: "))


(setq newlen (+ plotpt newlen))
(setq pt (vlax-curve-getpointatdist ent newlen))
(setq ang (angle '(0.0 0.0) (trans (vlax-curve-getfirstderiv ent (vlax-curve-getparamatpoint ent pt)) 0 ent t)))
(initget "A B L R")
  (setq side (getkword "\nWhich side Above or Below [A/B/L/R]: "))
(cond
  ((or
   (= side "A")
   (= side "R"))
   (setq ang (+ ang 1.5708))
   )
  ((or
    (= side "B")
    (= side "L"))
    (setq ang (- ang 1.5708))
    )
  )
 
(setq obj (vlax-ename->vla-object ent))
(setq pt (polar pt ang offset))
(entmakex (list
    (cons 0 "POINT")
    (cons 10 pt)
    (cons 8 "non-print")
    )
  )
  (princ "\Point created")
  )
« Last Edit: February 22, 2017, 12:14:49 PM by dubb »