Developing

Developing solutions can be a challenge and on this page notes are maintained - maybe they can help you!


vla-get vla-put

You can control much with this combo. The question is: How to use it? Paste and study on the command line (F2)...

If you paste:

(setq ss (vlax-get-acad-object))

... you get an object - assigned to variable ss. Next you want to know the properties of ss:

(vlax-dump-object ss)

Now you know the properties and one of the entries is preferences. Let's see what it offers, if you paste each line...

(setq ss (vla-get-preferences (vlax-get-acad-object)))
(vlax-dump-object ss)

... you get an object files. So the next step:

(setq ss (vla-get-files (vla-get-preferences (vlax-get-acad-object))))
(vlax-dump-object ss)

Now we have all files settings. As long is there is not a (RO) text (Read Only), we can change it.

For example, we have all plotter configurations on a server drive. The current locations are:

(vla-get-printerconfigpath ss)
(vla-get-printerdescpath ss)
(vla-get-printerstylesheetpath ss)

We assign a different location:

(vla-put-printerconfigpath ss "x:\\cad_users\\19.1\\plotters")
(vla-put-printerdescpath ss "x:\\cad_users\\19.1\\plotters\\pmpfiles")
(vla-put-printerstylesheetpath ss "x:\\cad_users\\19.1\\plotters\\plotstyles")

Cool?

In summary: You start with (vlax-get-acad-object) for building a selection set, making it complexer as described, where (vlax-dump-object ss) is your friend. If you know the properties by using "get", you can change them with "put".

Easy Peacy!

LISP and groups

How can we handle named and unnamed groups?

If you want to do operations within a group you can use what is documented here: http://adndevblog.typepad.com/autocad/2012/12/how-to-add-a-group-in-a-selection-set-from-an-autolisp-function.html. A cached version:

(defun selgrp (grpname)
   ;; grpname is the group name, it accepts
   ;; unnamed groupnames, such as *A1
   (setq grp (dictsearch (namedobjdict) "ACAD_GROUP"))
   (setq a1 (dictsearch (cdr (assoc -1 grp)) grpname))
   (setq ss (ssadd))
   (while (/= (assoc 340 a1) nil)
      (setq ent (assoc 340 a1))
      (setq ss (ssadd (cdr ent) ss))
      (setq a1 (subst (cons 0 "") ent a1))
   )
   ss
)

Settings in LISP file

This is always under construction, but you record settings:

(setq ortho_org (getvar "orthomode"))

... and more as needed. Then you code your program and change ORTHOMODE as needed:

(setvar "orthomode" 1)

However, a user should get all changed settings back after your code is finished. So you end with:

(setvar "orthomode" ortho_org)

If you do it properly, you put that line of code in your error handler too, in particular because many people press Esc too frequently.

You probably know all this, or not, but a particular setting needs a different approach: OSMODE or object snap mode. This is a number, a bitsum of many settings:

0 None 
1 Endpoint 
2 Midpoint 
4 Center 
8 Node 
16 Quadrant 
32 Intersection 
64 Insertion 
128 Perpendicular 
256 Tangent 
512 Nearest 
1024 Quick 
2048 Apparent Intersection 
4096 Extension
8192 Parallel

For example, value 511 (green "P" button) is a bitsum of 1+2+4+8+16+32+64+128+256=515

You could use a construction as illustrated with ORTHOMODE, but you will find out it doesn't work perfectly. Why? Because OSNAP on and off is also included in the code.

To illustrate: Do OSMODE 1. OSMODE is set to 1 (check). Press F3 for turning off object snap. This is not the same is setting it to 0, it is just a switch to turn off or turn on to the previous settings (read this twice). Do OSMODE and see that it changed to 1+16384=16385.

So you want to turn it off and simply substract 16384? That works for 16385, but not if the value is unknown and set by the user, for example 1-16384. So we need a different solution. We use a function called boole for truth tables.

Turning OSNAP off:

(setvar "osmode" (boole 7 (getvar "osmode") 16384))

Turning OSNAP on:

(setvar "osmode" (boole 2 (getvar "osmode") 16384))

Toggle OSNAP:

(setvar "osmode" (boole 6 (getvar "osmode") 16384))

This site is hosted by NedCAD.

De inhoud van deze site wordt aangeboden zoals het is, zonder enige vorm van garantie en heeft verschillende licenties. Meer informatie over licenties staat hier.