Jump to content

Electrical Homerun Lisp


caditnow

Recommended Posts

Hey all. I'm using AutoCAD 2016 and I'm trying to use the Homerun lisp below with no success. Others with older version of CAD are able to use.

I'm hoping someone on this site will help me find a fix.

 

 

(DEFUN C:HR (/ ORTM P1 P2 P3 AR AL RA P4 AN2 AN3 A3 AN P5 AN4 AR1)

(SETQ ORTM (GETVAR "ORTHOMODE"))

(SETVAR "ORTHOMODE" 0)

(PROMPT "\nPICK POINT TO START FROM")

(SETQ P1 (GETPOINT))

(PROMPT "\nPICK POINT FOR ARROW HEAD")

(SETQ P2 (GETPOINT))

(COMMAND "ARC" P1 "E" P2 "D" PAUSE)

(SETQ P3 (OSNAP P1 "QUI,MID"))

(SETQ AR (ENTLAST))

(SETQ AL (ENTGET(ENTLAST)))

(SETQ RA (CDR (ASSOC 40 AL)))

(SETQ P4 (CDR (ASSOC 10 AL)))

(SETQ AN2 (ANGLE P4 P2))

(SETQ AN3 (ANGLE P4 P3))

(SETQ A3 (ANGLE P4 P3))

(SETQ AN (ANGLE P1 P2))

(COND

((OR (> AN (* PI 1.5)) (

(IF (AND (> A3 0.0) (

(SETQ AN2 (ANGLE P4 P2))

(SETQ AN2 (ANGLE P2 P4))

)

)

((AND ( AN (* PI 0.5))) ;;;Modifications were done

(IF (AND (> A3 0.0) (

(SETQ AN2 (ANGLE P2 P4))

(SETQ AN2 (ANGLE P4 P2))

)

)

)

(SETQ P5 (POLAR P2 (+ AN2 (* PI 0.5)) (* 0.15 (GETVAR "DIMSCALE"))))

(SETQ AN4 (ANGLE P4 P5))

(SETQ P5 (POLAR P4 AN4 RA))

 

 

 

(COMMAND "PLINE" P2 "W" "0" (* 0.06 (GETVAR "DIMSCALE")) P5 "W" "0" "0" P2 "")

(SETQ AR1 (ENTLAST))

(COMMAND "PEDIT" AR "Y" "J" AR1 "" "X")

(setq ar(entlast))

(SETVAR "ORTHOMODE" ortm)

)

Link to comment
Share on other sites

sorry about the bad pasting.

 

 

the error i'm getting is:

 

 

Specify center point of arc (hold Ctrl to switch direction) or [Angle/Direction/Radius]: D

Specify tangent direction for the start point of arc (hold Ctrl to switch direction):

Command: ; error: bad argument type: 2D/3D point: nil

I tried debugging this with vlisp and it seemed to fail on line:

(SETQ AN3 (ANGLE P4 P3))

Link to comment
Share on other sites

osnap is a reserved word lisp is looking for a defun here

(SETQ P3 (OSNAP P1 "QUI,MID")) ;wrong 
(SETQ P3 (GETPOINT P1 "QUI,MID")) ;works

Edited by BIGAL
Link to comment
Share on other sites

thank you BIGAL, but I must be doing something wrong.

 

 

I replaced

 

 

(SETQ P3 (OSNAP P1 "QUI,MID"))

 

 

with

 

 

(SETQ P3 (GETPOINT P1 "QUI,MID"))

 

 

but still no luck. Were you able to try this in ACAD 2016?

Link to comment
Share on other sites

BIGAL, this is wrong :

(setq p3 (getpoint p1 "QUI,MID"))

as string after point specification only represents message and not OSNAP-s... Instead try to (setvar 'OSMODE num) before call of (getpoint) or set OSNAP-s with command directly before (getpoint) : (command "_.OSNAP" "QUI,MID")

 

M.R.

Link to comment
Share on other sites

thank you M.R.

 

 

I'm not good at lisp so I'm not sure exactly how you're modifying the lisp.

 

 

would you mind posting a before and after of the portions you are modifying?

Link to comment
Share on other sites

(SETQ P3 (OSNAP P1 "QUI,MID"))

 

Should work IF p1 is a valid point list on an entity that the midpoint can be extracted from and within the current pickbox aperture size. Otherwise (osnap) will return nil and should ' error: bad argument type: 2D/3D point: nil ' to any function requiring a point list value parameter. ie (angle)

 

-Davud

Link to comment
Share on other sites

Just use another method to get your midpoint.

Here's one way:

 

(DEFUN C:HR (/ ORTM P1 P2 P3 AR AL RA P4 AN2 AN3 A3 AN P5 AN4 AR1)
(SETQ ORTM (GETVAR "ORTHOMODE"))
(SETVAR "ORTHOMODE" 0)
(PROMPT "\nPICK POINT TO START FROM")
(SETQ P1 (GETPOINT))
(PROMPT "\nPICK POINT FOR ARROW HEAD")
(SETQ P2 (GETPOINT))
(COMMAND "ARC" P1 "E" P2 "D" PAUSE)
[color="red"](SETQ P3 (POLAR P1 (ANGLE P1 P2)(/ (DISTANCE P1 P2) 2.0)))[/color]
;(SETQ P3 (OSNAP P1 "QUI,MID"))
(SETQ AR (ENTLAST)) 
(SETQ AL (ENTGET(ENTLAST)))
(SETQ RA (CDR (ASSOC 40 AL)))
(SETQ P4 (CDR (ASSOC 10 AL)))
(SETQ AN2 (ANGLE P4 P2))
(SETQ AN3 (ANGLE P4 P3))
(SETQ A3 (ANGLE P4 P3))
(SETQ AN (ANGLE P1 P2))
(COND
((OR (> AN (* PI 1.5)) (< AN (* PI 0.5))) 
(IF (AND (> A3 0.0) (< A3 PI))
(SETQ AN2 (ANGLE P4 P2))
(SETQ AN2 (ANGLE P2 P4))
)
)
((AND (< AN (* PI 1.5)) (> AN (* PI 0.5))) ;;;Modifications were done 
(IF (AND (> A3 0.0) (< A3 PI)) ;;;here
(SETQ AN2 (ANGLE P2 P4))
(SETQ AN2 (ANGLE P4 P2))
)
)
)
(SETQ P5 (POLAR P2 (+ AN2 (* PI 0.5)) (* 0.15 (GETVAR "DIMSCALE"))))
(SETQ AN4 (ANGLE P4 P5))
(SETQ P5 (POLAR P4 AN4 RA))



(COMMAND "PLINE" P2 "W" "0" (* 0.06 (GETVAR "DIMSCALE")) P5 "W" "0" "0" P2 "")
(SETQ AR1 (ENTLAST))
(COMMAND "PEDIT" AR "Y" "J" AR1 "" "X")
(setq ar(entlast))
(SETVAR "ORTHOMODE" ortm)
)

Link to comment
Share on other sites

The way a few of us would have tackled it.

 

(SETVAR "ORTHOMODE" 0)
(setq oldsnap (getvar "osmode"))
.........
........
(setvar "osmode" 1026) ; this is qui mid
(SETQ P3 (getpoint P1 "Pick next point"))
(setvar "osmode" oldsnap) ; snaps back to what they were
........

Link to comment
Share on other sites

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