PDA

View Full Version : Double Line Offset



BCrouse
2004-06-01, 02:26 PM
Is there is a lisp routine that is similar to offset. You have a line for a center line and you want to have a lines on each side of it. So you pick the center line just like offset and you indicate what is the distance between the center line. And when you enter the value and hit enter. You have a line, a center line and a line.

Also you could pick the center line and after you do everything from the above idea. The center line the is erased. with this one you would have a line, a space and a line.


Thank you,

Brad

RobertB
2004-06-01, 10:51 PM
There might be one in the Exchange. Search there first. If there isn't one there, we can help you write the program.

wpeacock
2004-06-02, 02:05 AM
There is a good lisp example at CADALYST>GET THE CODE> APRIL 2004 called OFFSET LINE by Will Deloach.

This might just be what you are looking for....

peter
2004-06-02, 12:44 PM
(defun C:OL ()
(while (not (setq lstSelection (entsel "\nSelect object to offset: ")))
(princ "\nNull Selection please try again: ")
)
(setq objSelection (vlax-ename->vla-object (car lstSelection))
lstPoint (vlax-curve-getClosestPointTo objSelection
(cadr lstSelection))
sngParam (vlax-curve-getParamAtPoint objSelection lstPoint)
sngSlope (vlax-curve-getFirstDeriv objSelection sngParam)
sngAngle (+ (angle (list 0.0 0.0 0.0) sngSlope) (/ pi 2.0))
sngDistance (getdist "\nEnter offset distance: ")
)
(vl-cmdf "offset" sngDistance
lstPoint
(polar lstPoint sngAngle 0.1)
""
)
(vl-cmdf "offset" sngDistance
lstPoint
(polar lstPoint (+ pi sngAngle) 0.1) ""
)
(if (not (tblsearch "ltype" "center"))
(vla-load (vla-get-linetypes
(vla-get-activedocument
(vlax-get-acad-object)
)
)
"center"
"ACAD.LIN"
)
)
(vla-put-linetype objSelection "center")
(prin1)
)

RobertB
2004-06-02, 02:50 PM
Well, if you are going to use ActiveX, why not use the Offset method? ;-)


(defun C:OL (/ pickEnt pickObj offDist)
(vl-load-com)
(setvar "ErrNo" 0)
(while (and (not (setq pickEnt (entsel))) (/= 52 (getvar "ErrNo"))))
(cond ((and pickEnt
(setq pickObj (vlax-EName->vla-Object (car pickEnt)))
(progn (initget 6)
(setq offDist (getdist "\nSpecify offset distance: "))))
(vla-Offset pickObj offDist)
(vla-Offset pickObj (- offDist))
(I:PutCL pickObj)))
(princ))

(defun I:PutCL (myObj / linetypes ltName)
(setq linetypes (vla-Get-Linetypes (vla-Get-Document myObj))
ltName "Center")
(cond ((vl-catch-all-error-p
(vl-catch-all-apply 'vla-Item (list linetypes ltName)))
(vla-Load linetypes
ltName
(cond ((= (getvar "Measurement") 0) "Acad.lin")
("AcadISO.lin")))))
(vla-Put-Linetype myObj ltName))

peter
2004-06-03, 12:22 PM
I liked the errno condition and utilized the vla-offset method and converted to this.

Peter Jamtgaard



(defun C:OL (/ lstSelection objSelection sngDistance)
(while (and (not (setq lstSelection (entsel "\nSelect object to offset: ")))
(/= (getvar "ErrNo") 52)
)
(princ "\nNull Selection please try again: ")
)
(if lstSelection
(progn
(setq objSelection (vlax-ename->vla-object (car lstSelection))
sngDistance (getdist "\nEnter offset distance: ")
)
(vla-offset objSelection sngDistance)
(vla-offset objSelection (- sngDistance))
(if (not (tblsearch "ltype" "center"))
(vla-load (vla-get-linetypes
(vla-get-activedocument
(vlax-get-acad-object)
)
)
"center"
"ACAD.LIN"
)
)
(vla-put-linetype objSelection "center")
)
)
(prin1)
)

whdjr
2004-06-04, 12:24 PM
Here is my code that was published in the Cadalyst Mag.:


(defun c:ol (/ ent dist obj kwrd)
(vl-load-com)
(while (not ent)
(if (eq (setq ent (car (entsel "\nSelect line to offset: ")))
nil
)
(princ "\nThat was not a line. Please select again: ")
)
)
(initget (+ 1 2 4 64))
(setq dist (getdist "\nEnter offset distance: "))
(initget (+ 2 4) "Yes No")
(setq kwrd (getkword "\nDelete original object [Yes/No] <Yes>: "))
(if (/= kwrd "No")
(setq kwrd "Yes")
)
(setq obj (vlax-ename->vla-object ent))
(vla-offset obj dist)
(vla-offset obj (* dist -1))
(if (eq kwrd "Yes")
(vla-erase obj)
)
(princ)
)

Hope this helps,

Will DeLoach

BrenBren
2004-06-04, 01:29 PM
It's like dueling code...I hear banjo's playing in the distance...Robert, your up next:D

peter
2004-06-04, 03:16 PM
Brenda,

It isn't necessarily dueling code. It is evolving code.

I am frequently shown new approaches and techniques when I present code. In this case Robert was correct in his commentary of my first post. I then updated my code to encorporate his suggestions.

Humility is a necessary virtue to remain teachable.

Keeping an open mind...Be quick to see where others are right... Accept criticism as help instead of feeling it is a put down.

OK I will stop with the philosophy lecture....

I am read for another topic for discussion.

Peter Jamtgaard

RobertB
2004-06-04, 04:03 PM
Here is my code that was published in the Cadalyst Mag.:

Will, I've got some comments, I hope you don't mind.


(defun c:ol (/ ent dist obj kwrd)
(vl-load-com) ;<-good!
(while (not ent) ;<- this sort of loop is hard to get out of, see my code
(if (eq (setq ent (car (entsel "\nSelect line to offset: "))) ;<- (if (not (setq...)))
nil ;<- testing for nil is unneeded, use LISP's return values directly
)
(princ "\nThat was not a line. Please select again: ") ;<- what if I pick a circle?
)
)
(initget (+ 1 2 4 64)) ;<- use of the Z-blocker was nice
(setq dist (getdist "\nEnter offset distance: "))
(initget (+ 2 4) "Yes No") ;<- bits 2 and 4 server no purpose in (getkword)
(setq kwrd (getkword "\nDelete original object [Yes/No] <Yes>: ")) ;<- 2000-style options, good!
(if (/= kwrd "No") ;<- this statement is unneeded, see below
(setq kwrd "Yes")
)
(setq obj (vlax-ename->vla-object ent))
(vla-offset obj dist)
(vla-offset obj (* dist -1))
(if (eq kwrd "Yes") ;<- (/= kwrd "No")
(vla-erase obj)
)
(princ)
)

ndikesh708202
2015-09-04, 06:31 AM
Hi Peter,

i'm new to this site and this post is too old :D , i hope you guys are still available for some help.

this lisp is almost close to what i need, can anyone help me out here??

Regards

CCarleton
2015-09-10, 08:59 PM
Ndikesh,

Can you describe what you need altered/different from the original code?