PDA

View Full Version : Command, vl-cmdf and command-s Autocad 2015



l3ch
2015-01-30, 10:49 AM
Hi,

If ListPoints is a list of points and R is a distance,

with Autocad2015:

Case 1:


(mapcar '(lambda (pt) (command "_circle" pr R)) ListPoints)


returns: VVC: Internal Error

Case 2:


(mapcar '(lambda (pt) (vl-cmdf "_circle" pr R)) ListPoints)


returns: VVC: Internal Error

Case 3:


(mapcar '(lambda (pt) (command-s "_circle" pr R)) ListPoints)


Works Ok.

With Autocad2013 case 1 and case 2 work Ok. Why not now?

Command-s can avoid problems, but... if the order was:



(mapcar '(lambda (pt) (vl-cmdf "_pline" pt)) ListPoints)


command-s doesn't generate a single pline.

BlackBox
2015-01-30, 01:12 PM
Kean's AutoCAD 2015: calling commands (http://through-the-interface.typepad.com/through_the_interface/2014/03/autocad-2015-calling-commands.html) article may be able to provide some clarification... Put simply the ObjectARX functions were modified, which LISP is ultimately dependent on, and despite Autodesk generally handling which new 'correct' ARX call to make in the LispFunction code-behind, without changing the calling LISP, there are instances where Command-s is needed as you're already aware.

Cheers

BlackBox
2015-01-30, 01:20 PM
Also, FWIW -



(vl-load-com)

(defun _MakeCircles (doc points radius / oSpace circles)
(setq oSpace (vlax-get doc
(if (= 1 (getvar 'cvport))
'paperspace
'modelspace
)
)
)
(foreach pt points
(setq circles
(cons (vla-addcircle oSpace (vlax-3d-point pt) radius)
circles
)
)
)
(reverse circles)
)

Tharwat
2015-01-30, 05:23 PM
To work with entmake(x) is much better than the use of command calls specially in lisps .



(mapcar '(lambda (pt) (entmake (list '(0 . "CIRCLE") (cons 10 pt) (cons 40 R)))) ListPoints)

l3ch
2015-02-02, 08:17 AM
Thank you, Tharwat, I will use your idea. I love plain Lisp.

But the main question is not how to draw circles but why suddenly command, vl-cmdf don't work. I have lot of codes, and I have never hadd problems with new autocad versions, i don't understand why now.

By the way, how can I solve the problema with the pline?

BlackBox
2015-02-02, 03:10 PM
I love plain Lisp.


I opt for Visual LISP for ease of supporting UNDO functionality, which 'plain LISP' can only accomplish with Command calls, or to use Visual LISP for the UNDO portion, in which case you'd just use same in the first place. Also, with any 'current' workstation, 'plain LISP' doesn't have any real, demonstrable difference in performance for end user, as is not as 'plain' to read (DXF has always been cheeky that way).




But the main question is not how to draw circles but why suddenly command, vl-cmdf don't work. I have lot of codes, and I have never hadd problems with new autocad versions, i don't understand why now.


Please read Kean's article, linked above.




By the way, how can I solve the problema with the pline?




(vl-load-com)

(defun _AddPolyline (doc points)
;; Example: (_AddPolyline acDoc listPoints)
(if (= (rem (length (setq points (apply 'append points))) 3) 0)
(vla-addpolyline
(vlax-get doc
(if (= 1 (getvar 'cvport))
'paperspace
'modelspace
)
)
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbDouble
(cons 0 (- (length points) 1))
)
points
)
)
)
)




Cheers

peter
2015-02-03, 07:28 PM
I noticed in your lambda expression(at the top) you have the argument (pt) but in the expression you have a variable pr

This is what I see above.


(mapcar '(lambda (pt) (vl-cmdf "_circle" pr R)) ListPoints)

Try


(mapcar '(lambda (pt) (vl-cmdf "_circle" PT R)) ListPoints)

Worked for me.

P=

l3ch
2015-02-04, 09:00 AM
Thanks, Peter, it was a misprint. I thought everybody caught the idea and I didn't want to add another message with the correction. I apologize for any inconveniences.

l3ch
2015-02-04, 09:10 AM
Thanks, BlackBox. Kean'sarticle was hard for me, but I get the idea. Is a matter of fact, Autocad2015.

Thanks again for your code with the pline solution.

I have rewritten my codes, where I used (mapcar '(lambda... with lots of commands and so, I have created small subroutines (like _AddPolyline).

BlackBox
2015-02-04, 01:48 PM
Thanks, BlackBox. Kean'sarticle was hard for me, but I get the idea. Is a matter of fact, Autocad2015.

Thanks again for your code with the pline solution.

I have rewritten my codes, where I used (mapcar '(lambda... with lots of commands and so, I have created small subroutines (like _AddPolyline).

You're welcome, l3ch; reading Kean's (and others') articles gets easier the more you understand. :beer:

As Peter aptly demonstrated, there's nothing wrong with the Command version either. To my mind it's more about using the right method for any given task, so as a small example, you could not use the command option in a ObjectDBX batch process, whereas you could use my offering, but you're unlikely to perform a batch process often.

Hope this makes (more?) sense.

Cheers

peter
2015-02-04, 08:56 PM
Blackbox is right...

There are lots of weapons in our arsenal.

You don't use a bazooka to go squirrel hunting.

IMHO, use command functions to get familiar with programming.

Migrate up to entity list manipulation and activeX when you want to grow.

Maybe play with some VBa on the way

Then move to C# or VB.net

The only way to improve your skills is to start coding and try to create functions that you see in your head.

Code daily.

Come here and ask questions...

P=

BlackBox
2015-02-04, 09:22 PM
Blackbox is right...

There are lots of weapons in our arsenal.

You don't use a bazooka to go squirrel hunting.

IMHO, use command functions to get familiar with programming.

Migrate up to entity list manipulation and activeX when you want to grow.

Maybe play with some VBa on the way

Then move to C# or VB.net

The only way to improve your skills is to start coding and try to create functions that you see in your head.

Code daily.

Come here and ask questions...


Well said, Peter. :beer:

l3ch
2015-02-06, 08:50 AM
I'm afraid both of you 're right. I hate and left C++ 20 years ago, I use Lisp since 1988 and I like it since then, it's something almost indecently; I really get incredible things with Lisp, til the point I see funny how Autocad takes years to provide tools I have developed long time before, so It's difficult for me to change my mind about new posibilities. But some of my codes are quite olds and maybe it's time to adapt them and why not? try all the weapons.

Thank you again for your help, it's good to know you will be there.

peter
2015-02-06, 05:36 PM
Like you I started programming LISP in the 80's (1986).

I can do incredible things with LISP, so I use it as a preferred language to develop in.

I have developed a lot of tools that Autodesk never even thought of.

I use .NET for things LISP cannot do or when function speed is critical.

LISP can do most things, it is much faster to code, it doesn't need to be "updated" every time MS updates a reference library...

I also am constantly rewriting code to my current style.

It amazes me how tight I can get my code, compared to the spaghetti code I started with.

2 cents...

P=