Jump to content

HELP! I am realy close on a XLine function and I need some final step help


Hutter7405

Recommended Posts

So with the help of the internet I created an XLine function that when I type XV or XH it puts a vertical or horizontal XLine on Defpoints layer and then automatically switches back to the layer you were on before the XH/XV function.

 

The problem is that when I place my first XLine, when I go to place my second XLine the function does its job and goes back to the layer I was on before. How do I make it so the function stays on Defpoints until you hit ESC then it returns to the original layer?

 

Thanks

 

What i have so far

 

(defun c: xv()(command "._xline" "_v")(princ))
(defun c: xh()(command "._xline" "_h")(princ))


(defun c: xh (/ p1 p2)
(setq cl (getvar "clayer"))
(command "-layer" "s" "defpoints" "")
(command "xline""_h")(princ)
(setvar "clayer" cl)
);defun


(defun c: xv (/ p1 p2)
(setq cl (getvar "clayer"))
(command "-layer" "s" "defpoints" "")
(command "xline""_v")(princ)
(setvar "clayer" cl)
);defun

Edited by Hutter7405
Link to comment
Share on other sites

Here's a nudge in the right direction:

 

(defun c:xh ( / cl )
   (setq cl (getvar 'clayer))
   (command "_.-layer" "_M" "defpoints" "" "_.xline" "_H")
   (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
   (setvar 'clayer cl)
   (princ)
)

Link to comment
Share on other sites

Your problem wouldn't exist if you entmake the XLINE instead of trying to script the commands. Using entmake to create the entity you simply specify group code 8 as "defpoints" and that is all you need to create the layer and place the entity in that layer.

I quote from my book AutoCAD expert's Visual LISP:

10.3. Creating entities with ENTMAKE.

The second way we can operate in the AutoCAD environment resorts to the object properties exposed in the form of association lists. These properties are managed through a series of functions whose names that begin with the ent... prefix.

In the chapter in which we described association lists we proposed as an example of this data structure the list that, after drawing a circle, is returned by the expression (entget (entlast)). We also explained how to retrieve a specific item from an association list using its key in the assoc function and how it was possible to replace a list item by using the subst function. We’ll now combine all this as a first approach to these methods in a function that makes multiple copies of a circle.

The ENTMAKE function.

The syntax of this function is: (entmake [entity-list]) where entity-list contains the entity definition information in a format similar to that returned by the entget function. The entity-list argument must contain all the information needed to define the entity. If any required data is omitted, entmake returns nil and the entity is not created. If the data omitted is not essential (e.g., the Layer name), then the value corresponding to the current system settings (e.g., the current Layer) will be used. The entity type (DXF code 0) should be the first or second item in entity-list. In case it is the second item it can only be preceded by an entity name (ename, DXF code -1) that will be ignored by entmake because the new entity will have its own ename. If entity-list includes a handle (a permanent identifier, DXF code 5) it will also be ignored for the same reason.

For entities that existed prior to AutoCAD Release 13 the values ​​associated with DXF code 100 are also ignored. Alternatives to the programmer are twofold: worrying about which entities require these codes, or simply including them always, knowing that in some cases -for example, circles, lines or points- they are not strictly necessary.

If entmake succeeds in creating the entity, it returns the entity list and otherwise nil, fact that could be used for error checking

Using entmake you can program a command like the following:

 

(defun C:XHV  (/ pt vec)
 (initget "Horizontal Vertical")
 (if (= (getkword "\nDraw XLINE [Horizontal/Vertical]: ")
        "Horizontal")
   (setq vec '(1 0 0))
   (setq vec '(0 1 0)))
 (while (setq pt (getpoint "\nSpecify a point: "))
   (entmake (list '(0 . "XLINE")
                  '(100 . "AcDbEntity")
                  '(8 . "defpoints")
                  '(100 . "AcDbXline")
                  (cons 10 pt)
                  (cons 11 vec)))))

This function which I posted earlier should be modified to take into account that the XLINE's group code 10 should be in WCS.

This should be taken into account if the UCS does not coincide with the WCS.

Also to reproduce the actual XLINE behavior the orientation vector should also depend on the current UCS, which can be obtained from the UCSXDIR and UCSYDIR system variables.

The code should then be like this:

(defun C:XHV  (/ pt vec)
 (initget "Horizontal Vertical")
 (if (= (getkword "\nDraw XLINE [Horizontal/Vertical]: ")
        "Horizontal")
   (setq vec (getvar "ucsxdir"))
   (setq vec (getvar "ucsydir")))
 (while (setq pt (trans (getpoint "\nSpecify a point: ") 1 0))
   (entmake (list '(0 . "XLINE")
                  '(100 . "AcDbEntity")
                  '(8 . "defpoints")
                  '(100 . "AcDbXline")
                  (cons 10 pt)
                  (cons 11 vec)))))

More information on my blog: lispexpert.blogspot.com

Edited by togores
Updated for non WCS states.
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...