Jump to content
trefan123

Add previous objects to group

Recommended Posts

trefan123

Good day,

What i know is dangerous.

I have a basic lisp that draws a couple of lines and arc's.

---------------

(command "LINE" IP P4 P5 P6 P16 P15 P14 "C")

(command "LINE" P1 P8 "")

(command "LINE" P11 P18 "")

(Command "arc" P5 P7 P8 "")

(Command "arc" P8 P9 P18 "")

(Command "arc" P18 P17 P15 "")

----------------------------------

I would like to group these items for ease of manipulation.

All help is appreciated.

Thanks

Peter

Share this post


Link to post
Share on other sites
Grrr

Hi,

something like:

(setq objlist (list (setq entity (entlast))))
(command "LINE" IP P4 P5 P6 P16 P15 P14 "C")
(command "LINE" P1 P8 "")
(command "LINE" P11 P18 "")
(Command "arc" P5 P7 P8 "")
(Command "arc" P8 P9 P18 "")
(Command "arc" P18 P17 P15 "")
(while (setq entity (entnext entity))
 (setq objlist (cons (vlax-ename->vla-object entity) objlist))
)
(vlax-invoke 
 (vla-add (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))) "*")
 'appenditems
 objlist
)

Share this post


Link to post
Share on other sites
Lee Mac

Here's another way, which may be easier to understand for a beginner:

(setq ent (entlast))
(while (setq tmp (entnext ent)) (setq ent tmp))
(command
   "_.line" "_non" IP   "_non" P4  "_non" P5 "_non" P6 "_non" P16 "_non" P15 "_non" P14 "_c"
   "_.line" "_non" P1   "_non" P8  ""
   "_.line" "_non" P11  "_non" P18 ""
   "_.arc"  "_non" P5   "_non" P7  "_non" P8
   "_.arc"  "_non" P8   "_non" P9  "_non" P18 
   "_.arc"  "_non" P18  "_non" P17 "_non" P15
   "_.-group" "_c" "*" "" 
)
(while (setq ent (entnext ent)) (command ent))
(command "")

 

@Grrr beware of circumstances in which the last entity in the database is complex (e.g. Heavy/3D polyline / attributed block)

Share this post


Link to post
Share on other sites
Grrr

@Grrr beware of circumstances in which the last entity in the database is complex (e.g. Heavy/3D polyline / attributed block)

 

Thanks Lee, I just understood what you did in the first two rows of your suggestion, and then I read your remark. :thumbsup:

 

Now I think that a subfunction that determines if an entity is parent (returns boolean), would pair nicely with entnext.

Share this post


Link to post
Share on other sites
trefan123

Thanks a lot. I seem to grasp what lee added, i did try the entlast previously ..just errors...

One question why put the non in front of the points?

Share this post


Link to post
Share on other sites
trefan123

Here is the complete lisp, must have had the old one loaded as it worked but the addition fails

(defun C:boltside (/ IP P1 P2 P3 SIZE)

;================make and choose color=========================

(command "LAYER" "M" "Steel" "c" "green" "" "")

(command "color" "white" "")

(setvar 'osmode 53)

;=================insertion point========================

(setvar "CMDECHO" 0)

(setvar "BLIPMODE" 0)

(setq IP (getpoint "\nInsertion Point: "))

(setvar "OSMODE" 0)

(setq SIZE (getreal "\nEnter the Nominal Bolt Size--Metric-: ")

)

;====================get all points===================

(setq P1 (polar IP (DTR 180.0) (* 0.4330 SIZE))

P2 (polar IP (DTR 180.0) (* 0.6495 SIZE))

P3 (polar IP (DTR 180.0) (* 0.7655 SIZE))

P4 (polar IP (DTR 180.0) (* 0.8660 SIZE))

P9 (polar IP (DTR 90.0) (* 0.8000 SIZE))

P8 (polar P1 (DTR 90.0) (* 0.7420 SIZE))

P7 (polar P2 (DTR 90.0) (* 0.8000 SIZE))

P6 (polar P3 (DTR 90.0) (* 0.8000 SIZE))

P5 (polar P4 (DTR 90.0) (* 0.7420 SIZE))

P11 (polar IP (DTR 0.0) (* 0.4330 SIZE))

P12 (polar IP (DTR 0.0) (* 0.6495 SIZE))

P13 (polar IP (DTR 0.0) (* 0.7655 SIZE))

P14 (polar IP (DTR 0.0) (* 0.8660 SIZE))

P18 (polar P11 (DTR 90.0) (* 0.7420 SIZE))

P17 (polar P12 (DTR 90.0) (* 0.8000 SIZE))

P16 (polar P13 (DTR 90.0) (* 0.8000 SIZE))

P15 (polar P14 (DTR 90.0) (* 0.7420 SIZE))

)

;==================draw nut=======================

(setq ent (entlast))

(while (setq tmp (entnext ent)) (setq ent tmp))

(command

"_.line" "_non" IP "_non" P4 "_non" P5 "_non" P6 "_non" P16 "_non" P15 "_non" P14 "_c"

"_.line" "_non" P1 "_non" P8 ""

"_.line" "_non" P11 "_non" P18 ""

"_.arc" "_non" P5 "_non" P7 "_non" P8

"_.arc" "_non" P8 "_non" P9 "_non" P18

"_.arc" "_non" P18 "_non" P17 "_non" P15

"_.-group" "_c" "*" ""

)

(while (setq ent (entnext ent)) (command ent))

(command "")

;================rotate to desired position=========================

(prompt "\nRotation Angle: ")

(command "ROTATE" "LAST" "" IP pause)

;================end=========================

(setvar 'osmode 53)

(princ)

)

Share this post


Link to post
Share on other sites
BIGAL

Just a suggestion

 

(setq a90 (/ pi 2.0)) ; this is 90 degrees
pi is 180 degrees use as is
(setq a180 pi)
(setq a270 (* pi 1.5)) this is 270 degrees

P3 (polar IP pi (* 0.7655 SIZE))
P18 (polar P11 a90 (* 0.7420 SIZE))

Share this post


Link to post
Share on other sites
trefan123

this was not copied

(defun DTR (a) ;degrees to radians function

(* PI (/ a 180.0))

)

Share this post


Link to post
Share on other sites
Lee Mac
One question why put the non in front of the points?

 

This command modifier is short for "none" and instructs AutoCAD to ignore all active Object Snap modes for the next point input.

Share this post


Link to post
Share on other sites
trefan123
This command modifier is short for "none" and instructs AutoCAD to ignore all active Object Snap modes for the next point input.

 

learn something every day..

thanks again

Share this post


Link to post
Share on other sites
Grrr
learn something every day..

 

ha! I live with that motto..

Share this post


Link to post
Share on other sites
BIGAL

trefan what I was getting at is the 90 180 270 are known values so you could predefine them in a startup lisp so no need for the dtr routine. Check out help on "Pi".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×