Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with custom Divide Command

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
240 Views, 3 Replies

Help with custom Divide Command

The following routine is looping divide command so you can intuitively
determine what you are after.
Could I get some expert opinion on streamlining it. I hope to learn
something from this. My big problem is understanding how to get the
points to be oriented realitive to the OCS of the profile being devided, as
well as the fact that I am probably breaking a bunch of cardinal rules of
programming.
**requires DOSLIB**
Thanks in advance
Rodney


(DEFUN C:DDV ()
(SETQ DP_PDMODE (GETVAR "PDMODE")
DP_PDSIZE (GETVAR "PDSIZE")
)
(SETVAR "PDMODE" 34)
(SETVAR "PDSIZE" 0.25)
(PROMPT "Select Object to Divide")
(WHILE (NOT (SETQ ENT (SSGET ":S" (LIST (CONS 0
"LINE,LWPOLYLINE,ARC,CIRCLE,ELLIPSE")))))
(IF (NOT ENT) (Prompt "\nInvalid Selection, Please try again...."))
)

(setq ent (ssname ent 0) etyp (cdr (assoc 0 (entget ent))))
(cond
((= etyp "LINE")
(setq start (cdr (assoc 10 (entget ent)) )
end (cdr (assoc 11 (entget ent)) )
)
)
((= etyp "LWPOLYLINE")
(setq start (cdr (assoc 10 (entget ent)) )
end (cdr (assoc 10 (reverse (entget ent))) )
)
)
((= etyp "ARC")

(setq PT1 (CDR (ASSOC 10 (entget ENT)))
start (POLAR PT1 (CDR (ASSOC 50 (entget ENT))) (CDR (ASSOC 40 (entget
ENT))))
end (POLAR PT1 (CDR (ASSOC 51 (entget ENT))) (CDR (ASSOC 40 (entget
ENT))))
)
)
((= etyp "ELLIPSE")

(setq
start (GETPOINT "\nSelect 1st Endpoint of Ellipse")
end (GETPOINT "\nSelect 1st Endpoint of Ellipse")
)
)
((= etyp "CIRCLE")

(setq PT1 nil
start nil
end nil
)
)
)


(SETQ FIEST 1)
(WHILE FIEST
(SETQ HMY (dos_getint "Points do you want to add" "Enter:" 2))
(command "UNDO" "MARK")
(COMMAND "DIVIDE" ENT HMY)
(NTH 2 (CDR (ASSOC 10 (ENTGET (ENTLAST)))))
(setq extdir (cdr (assoc 210 (entget ent))))
(if start
(PROGN (entmake (LIST '(0 . "POINT") (CONS 10 (TRANS (list (car
START)(cadr START) 0.0) ent 0)) (CONS 100 "AcDbPoint")(cons 210 extdir) ))
(entmake (LIST '(0 . "POINT") (CONS 10 (TRANS (list (car END)(cadr
END) 0.0) ent 0)) (CONS 100 "AcDbPoint")(cons 210 extdir) ))
)
)
(SETQ OK (dos_msgbox "Is this what you want?" "Change qty?" 4 3))
(if (= ok 6)
(setq fiest nil)
(command "undo" "bacK"))

)(princ)
)
3 REPLIES 3
Message 2 of 4
stevor
in reply to: Anonymous

Try setting the UCS to the object before creating the POINTs.
S
Message 3 of 4
Kent1Cooper
in reply to: Anonymous

You can simplify this quite a bit using some (vlax-curve-...) functions:

(vlax-curve-getStartPoint) and (vlax-curve-getEndPoint) will give you the 'start' and 'end' points for *any* kind of Dividable object, without your needing to extract its entity type, nor ask for any further User input such as you do for Ellipses.

(vlax-curve-isClosed) will tell you whether you need to add Points at the ends, without your having to set the 'start' variable to nil if it's a Circle [and you should also do that if it's a *closed* Polyline or Ellipse or Spline].

I also wonder about using (entmake) to put Points at the ends [where appropriate]. Usually I see that in routines by people who have an irrational fear of the (command) function, but you obviously don't, and that's a very much easier way to do it, *if* you just change the UCS to match the object as stevor suggested.

For a routine that does that, and even knows for which entity types it's appropriate, look at DivideMeasurePlus.lsp here:

http://discussion.autodesk.com/forums/message.jspa?messageID=6201035&tstart=0

Its DIV+ command already has the option to add points at the ends if you want them, and if appropriate, they will share the object's extrusion direction. It also works with more entity types than you're allowing.

I imagine it wouldn't be hard to make something from pieces of that, which would include your asking-whether-it-did-what-you-want option, and go back and do it again if the User wants a different number of points. It could probably even be coded somehow for simplicity of use, such as with a prompt that says "Press Enter to accept, + for one additional point, - for one fewer points."

--
Kent Cooper
Kent Cooper, AIA
Message 4 of 4
Kent1Cooper
in reply to: Anonymous

...like the attached, for instance.

Load up DiVideDynamic.lsp, and type DVD to use it. It asks you to select something, how many segments you want to divide it into, and whether or not you want to put Points at the ends, too.

It puts the Points in with the extrusion direction of the selected object when appropriate. When not [e.g. 3DPolylines, which have no extrusion direction and don't define a UCS], it puts them in the current Coordinate System.

Then it asks you to hit Enter/Space if it's OK [Esc works, too, though it's not mentioned in the prompt], or + if you want to increase the number of Points by 1, or - to decrease the number [that's the Dynamic part]. If you type + or -, it redoes the Divide command accordingly. You can keep hitting either one again, including changing direction, as long as it takes to get the result you want.

It will only let you decrease the number as far as validity allows, but that depends partly on whether you asked for Points at the ends. See the top of the file for details about that, and some other little things.

[It requires a Space or Enter after typing a + or -, which I would prefer were not needed. Does anyone know of a way to get it to respond to just the + or - keystroke alone?]

The same could be done with some kind of "Not-what-I-wanted" answer and a prompt for an explicit new number of segments, if that is preferable to the only-up-or-down-by-1 approach. And presumably it could also be made to have ordinary-Divide's Block option.

Oh, and it also remembers your choices [number of segments and whether or not to put Points at the ends], and offers them as defaults on subsequent use, which regular Divide doesn't do.

--
Kent Cooper


Kent1Cooper wrote...
....
I imagine it wouldn't be hard to make something from pieces of that [DIV+], which would include your asking-whether-it-did-what-you-want option, and go back and do it again if the User wants a different number of points. It could probably even be coded somehow for simplicity of use, such as with a prompt that says "Press Enter to accept, + for one additional point, - for one fewer points." Edited by: Kent1Cooper on Oct 16, 2009 2:58 PM
[added last sentence]
Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost