Jump to content

Making offset work in Draftsight.


SLiedtke

Recommended Posts

Hello everyone, I've found another issue that I think I'm a bit out of my depth in dealing with. My employer uses Draftsight on their computers, but I write my lisp code on my personal laptop where I have Autocad (student license). I use the visual studio code plugin to debug quickly.

The problem is that there are plenty of differences between Draftsight and Autocad in terms of lisp parsing, and I get the feeling that understanding all of them would take a level of understanding in computer science that I don't have.

Anyway, my current problem is with a command we use to add offsets to pieces we're cutting on the CNC machine. The command needs to:

 

-ignore the "cabinet" layer

-offset to the outside of all edges 3/16"

-put the final lines on the "CNC" layer

 

In Autocad, this works just fine: 

(defun c:cnc ( / p b l )
  (setq b (sl:boundary))
  (command "offset" "3/16" b '(0.0 0.0 0.0)"")
  (vl-cmdf "erase" b "")
)

(defun sl:boundary ( / p g n e)
  (setq g 0
        e (cdr(assoc -1(entget (entlast))))
        l (getvar 'clayer)
  )
  (while (= g 0)
    (setq p (getpoint "Select center of object"))
    (vl-cmdf "_.-layer" "freeze" "cabinet" "set" "cnc" "")
    (vl-cmdf "boundary" "a" "i" "n" "+x" "" p "")
    (vl-cmdf "_.-layer" "thaw" "cabinet" "set" l "")
    (setq n (cdr(assoc -1(entget(entlast)))))
    (cond ((not(equal e n ))(setq g 1)))
  )
  n
)

(I offset toward the point '(0.0 0.0 0.0) because that point will never be inside one of the shapes)

 

In Draftsight, this command always offsets the "boundary" lines by the last distance used by the offset tool, instead of 3/16". The only way I've been able to prevent this is to take over the placement step 

...
(command "offset" "3/16" entity pause)
...

This severely limits the tool's efficiency and scale-ability, though (I'd like to make a version at some point which does this for all shapes with a "cnc" tag in the future, but getting it to work at all seems like an important first step).

I'm happy to solve this using ActiveX, but Draftsight is missing quite a few of those statements.

 

Also, I noticed that in trying to fix this, I totally broke the tool's ability to let the user try again after missing a closed shape, so there's that too haha.

Link to comment
Share on other sites

This is why I try to stay away from using (command it has the highest chance not to work between software. They say they use visual lisp so give this a try.

 

(defun c:cnc ( / p b l )
  ;(setq b (sl:boundary)) ;this doesn't set b to the offset in sl:boundary
  (sl:boundary)
  (vla-offset (vlax-ename->vla-object (setq b (entlast))) 0.1875) ;neg to offset the other direction
  ;(command "offset" "3/16" b '(0.0 0.0 0.0)"")
  (entdel b) ;deletes entity by name
  ;(vl-cmdf "erase" b "")
)
(defun sl:boundary ( / p g n e)
  (setq Drawing (vla-get-activedocument (vlax-get-acad-object))) ;needed for regen for some visual lisp
  ;(setq g 0 ;g not needed
  (setq ;e (cdr(assoc -1(entget (entlast))))
        e (entlast)
        l (getvar 'clayer)
  )
  (while (eq e (entlast)) ;misclick check? 
    (setq p (getpoint "Select Inside Object: "))
    (vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-true) ;freeze layer Cabient
    (vla-Regen Drawing acAllViewports)
    (setvar 'clayer "cnc") ;set cnc to current layer
    ;(vl-cmdf "_.-layer" "freeze" "cabinet" "set" "cnc" "")
    (vl-cmdf "boundary" "a" "i" "n" "+x" "" p "")
    (vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-false) ;thaw layer Cabinet
    (vla-Regen Drawing acAllViewports)
    (setvar 'clayer l) ;set current layer back to 
    ;(vl-cmdf "_.-layer" "thaw" "cabinet" "set" l "")
    ;(setq n (cdr(assoc -1(entget(entlast)))))
    ;(cond ((not(equal e n ))(setq g 1)))
    ;(if (not (eq e (entlast))) (setq g 1))
  )
)

 

Edited by mhupp
updated regen
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the late response. 

Other than one problem, this worked great!

I couldn't get freezing to work with the VLA commands, though. This problem even persists in Autocad. 

This will freeze the cabinet layer just fine:

(vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-true)

This doesn't seem to thaw the layer:

(vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-false)

 

To make things even more confusing, it looks like the vla command doesn't freeze the layer completely. I'm wondering if this might be why it wont thaw.

 

before freeze:

image.png.e27a63f13e00fe0d3b6ece538d09a97c.png

 

after freeze:

1441207622_deleteme.thumb.png.af09a8e183d94008e88fc370348d4dee.png

 

Also, I've simplified the code to test these statements, to try to limit the variables.

(defun c:qfrz ()
  (vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-true)
  (getpoint)
  (vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-false)
)

 

  • Agree 1
Link to comment
Share on other sites

Seems you need to use regen to "show" the updated state. Weird freezing layers works without a regen but not for thawing them. as for not showing up in the drop down menu. it probably doesn't update the status in the middle of a lisp. Adding regen command after both should fix this.

 

(defun c:frz ()
  (setq Drawing (vla-get-activedocument (vlax-get-acad-object))) ;needed for regen
  (vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-true)
  (vla-Regen Drawing acAllViewports)
  (getpoint)
  (vla-put-freeze (vlax-ename->vla-object (tblobjname "layer" "Cabinet")) :vlax-false)
  (vla-Regen Drawing acAllViewports)
)

 

--edit

Same thing with updating a block with lisp if you don't regen it won't show the updates.

 

Also updated original code above.

Edited by mhupp
  • Thanks 1
Link to comment
Share on other sites

If you last offset was 3/16 what does (getvar 'offsetdist) return is it, 0.1875 so maybe use (setvar 'offsetdist 0.1875) and (command "offset" "" b '(0.0 0.0 0.0) "") I am metric so always whole numbers.

 

Enter offset distance or [Through point/Erase/Layer] <3/16">:
Cancel
: (getvar 'offsetdist)
0.1875

Edited by BIGAL
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...