vimcruz Posted February 7, 2014 Posted February 7, 2014 I've been searching a lot (like A LOT) about how to make a group via autolisp and finally I made it work. Now, looking around I saw some codes with so much lines than mine. So the question is, what's the difference between using this: (command "_.group" "c" "*" "group_desc" sset "") and some commands with "vl-something". Greetings from Mexico. PS. If anything, here's the piece of code: (defun c:mkgrp() (setq p1 (getpoint "P1")) (setq p2 (getcorner p1 "P2")) (setq set1 (ssget "_C" p1 p2)) (command "_.group" "c" "*" "group_desc" set1 "") ) Quote
Jef! Posted February 8, 2014 Posted February 8, 2014 Hi vimcruz, and welcome to the forum. I'm not very familiar with groups, but at the first glance both seems to do the same. To start with, even only using autocad directly (with commands) you can achieve the same goal by many different paths. Lets say you want to modelize a tube, you can: -draw 2 circles, make 2 regions out of them, subtract the smaller from the bigger section, than extrude. -draw 2 circles, extrude them both, then subtract the inner cylinder from the outer cylinder -draw half of the section then revolve it around the center axis. Basically it is the same with code, but moreover, with code you can use plain commands (like your first example), you can use lisp (like your 2nd example), you could use Visual lisp (vl-something like you said), you could even use vb, vba, active-x, .net. They all are (beside the commands) simply different language that autocad can interpret, some of them with no add on, like lisp and visual lisp. All the different paths can ultimately lead to the same goal, and each language have their advantages. While any autocad users can make basic lisps using (command "") type of writing, some things can be achieved only or easily with lisp. Some will say that to achieve "that thing" is faster with lisp than with commands, and they are right, but with today's computers, for common routines, instead of taking 1.2 thousandths of a second by lisp it can take 3.5 thousandths with commands. So taking few hours to transfer a command lisp to a pure lisp language routine could be anti-productive. You will have to run the routine millions of time for it to be profitable. Take the path that suit your needs. Knowing lisp/visual lisp is never lost though because it is very powerful and polyvalent languages... There are many ways to "skin the cat"! Quote
BIGAL Posted February 8, 2014 Posted February 8, 2014 Not sure why you are making a group when you have done a ssget which is a "group" of objects. Quote
vimcruz Posted February 8, 2014 Author Posted February 8, 2014 Thx for the explanation, Jeff! Not sure why you are making a group when you have done a ssget which is a "group" of objects. didn't know that. I recently started working with autocad 2013 and autolisp. I think a "group" is a selectable object perhaps?, does ssget has the same "habilities"?. Could you elaborate? Quote
Jef! Posted February 8, 2014 Posted February 8, 2014 Yes totally: agroup is selectable (with the mouse) ssget can be used with lisp while a "group" (in cad) act more or less like a block, enabling the manipulation of all entities within it at the same time on the command line selecting it with the mouse. That being said, I never saw any advantages of using groups instead of blocks, but many inconvenients. Maybe simply a question of habits. Quote
vimcruz Posted February 8, 2014 Author Posted February 8, 2014 Thx again, Jef!. All seems so clear now. Quote
Lee Mac Posted February 8, 2014 Posted February 8, 2014 and some commands with "vl-something". (defun c:mygroup ( / i l s ) (if (setq s (ssget)) (progn (repeat (setq i (sslength s)) (setq l (cons (vlax-ename->vla-object (ssname s (setq i (1- i)))) l)) ) (vlax-invoke (vla-add (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))) "*") 'appenditems l ) ) ) (princ) ) (vl-load-com) (princ) I explain some of the differences in this post. Quote
ColinHolloway Posted October 20, 2015 Posted October 20, 2015 (defun c:mygroup ( / i l s ) (if (setq s (ssget)) (progn (repeat (setq i (sslength s)) (setq l (cons (vlax-ename->vla-object (ssname s (setq i (1- i)))) l)) ) (vlax-invoke (vla-add (vla-get-groups (vla-get-activedocument (vlax-get-acad-object))) "*") 'appenditems l ) ) ) (princ) ) (vl-load-com) (princ) I explain some of the differences in this post. Hi Lee, It has been a while since I worked with creating groups so finding this old post looks like what I need. However... Loading and running it exactly as you have posted gives the following error in AutoCAD 2014: Command: MYGROUP Select objects: Specify opposite corner: 4 found Select objects: bad argument type: stringp nil Command: I am sure I have used similar code in the past so I'm stumped as to why this is failing. Any thoughts? Colin Holloway Quote
Lee Mac Posted October 20, 2015 Posted October 20, 2015 I don't see anything in the code that would cause that error - the only string argument is the group name, which is being supplied as "*". Could you possibly double-check your results? Quote
ColinHolloway Posted October 20, 2015 Posted October 20, 2015 OK so here's the weirdest thing... I just tested this code snippet on another AutoCAD 2014 machine as well as a 2016 machine and (of course) it works as expected... but it still fails as described on that one machine! I have confirmed that the (vl-load-com) is definitely being loaded so I cannot see any reason for it not running either. I will try a repair or reinstall of AutoCAD on this machine and see of that solves the issue. Quote
Lee Mac Posted October 20, 2015 Posted October 20, 2015 Perhaps a protected symbol representing one of the functions has been inadvertently redefined? Quote
Recommended Posts
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.