Jump to content

Add previous objects to group


trefan123

Recommended Posts

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

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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