How to trim by visual lisp

How to trim by visual lisp

Anonymous
Not applicable
3,493 Views
13 Replies
Message 1 of 14

How to trim by visual lisp

Anonymous
Not applicable

Hello everyone

 

Just learning to use autocad & visual lisp for 1 week, and .. i have some question...

 

1.

    Where to find the command list guide:

 I've searched lots of website, but no one shows how to set the parameters.

 

for example: 

   BOOL Rectangle(
   int x1,
   int y1,
   int x2,
   int y2 
);
BOOL Rectangle(
   LPCRECT lpRect 
);

 

2.

    I've made the line as below ("before"), and i need to change them to "after".

 

If use mouse click, it is very simple by "trim", but I have no idea about how to make this by visual lisp.

 

46736772_329772067838815_1397009186142814208_n.png

 

the code i am editing:  (seems fillet is not a good idea)

 

(command "mirror" objLineD2 "" pt2 pt3 "n")
(setq objLineD4(entlast))
(command "move" objLineD4 "" ptMove0 ptMove1) ;
(setq objLineD4(entlast))


(command ".copy" objLineD1 "" ptMove0 ptMoveLB)
(setq objLineDummy01(entlast))
(command ".copy" objLineNeck "" ptMove0 ptMoveLeft)
(setq objLineDummy02(entlast))
(command ".copy" objLineD2 "" ptMove0 ptMoveLT)
(setq objLineDummy03(entlast))

(setq ptDummy_L01(polar ptDummy_L00 (+ nTheta 0) 3) )
(setq ptDummy_L02(polar ptDummy_L00 (- (* pi 2) nTheta ) 3) )


(command "line" ptDummy_L00 ptDummy_L01 "")
(setq objLineDummy11(entlast))
(command ".copy" objLineDummy11 "" ptMove0 ptMoveLT)
(setq objLineDummy12(entlast))
(command "line" ptDummy_L00 ptDummy_L02 "")
(setq objLineDummy13(entlast))
(command ".copy" objLineDummy13 "" ptMove0 ptMoveRT)
(setq objLineDummy14(entlast))


(setq ptBound_L (list (car pLT) (- (cadr pLT) nPitch_Y)))
(command "line" pLT ptBound_L "")
(setq objLineBound_L(entlast))

(command "fillet" "r" 0)
(command "fillet" objLineDummy11 objLineDummy14)

(command "fillet" objLineDummy01 objLineBound_L)
(command "fillet" objLineDummy01 objLineDummy02)
(command "fillet" objLineDummy02 objLineDummy03)
(command "fillet" objLineDummy03 objLineBound_L)

 

------------

 

Thank you.

0 Likes
Accepted solutions (1)
3,494 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant

Ok. First of all, this is a good place to start.

Your 1st point is not relevant to LISP.

Then - what is your "state before"? Is that some kind of export from some SW? Would be that always similar?

 

Post that example as dwg.

Message 3 of 14

Anonymous
Not applicable

Hi BeeKeeCZ,

 

Sorry, I'm not sure what is the "state before".

 

And the attachment are lsp file & dwg file.

 

Thank you.

0 Likes
Message 4 of 14

ВeekeeCZ
Consultant
Consultant

Ok, how about not trimming but make boundaries. See HERE how it works.

 

(defun c:LikeTrim (/ ss)

  (princ "\nObjects to be removed, ")
  (if (setq ss (ssget '((0 . "LINE"))))
    (progn
      (sssetfirst nil nil)
      (command-s "_.-BOUNDARY")
      (command "_.erase" ss "")))
  (princ))
Message 5 of 14

Anonymous
Not applicable

Thank you very much BeeKee CZ.

 

I'm trying to adding the code  into my .lsp file, got some problem.

 

1. replacing "select range" by ssDummy

 

2. but not sure how to input "mouse pt "x 3    by code.

 

 

 

 

; trying to select all lines into ssDummy

; how i input the mouse click point 
(setq ssDummy(ssadd))
(ssadd objLineDummy01 ssDummy)
(ssadd objLineDummy02 ssDummy)
(ssadd objLineDummy03 ssDummy)
(ssadd objLineDummy11 ssDummy)
(ssadd objLineDummy12 ssDummy)
(ssadd objLineDummy13 ssDummy)
(ssadd objLineDummy14 ssDummy)

(LikeTrim ssDummy)

 

(defun LikeTrim ( ss)

(princ "\nObjects to be removed, ")
(if (setq ss (obj)))
(progn
(sssetfirst nil nil)
(command-s "_.-BOUNDARY")
(command "_.erase" ss "")))
(princ))

0 Likes
Message 6 of 14

Anonymous
Not applicable

update my current code.

 

(setq ssDummy(ssadd))
(ssadd objLineDummy01 ssDummy)
(ssadd objLineDummy02 ssDummy)
(ssadd objLineDummy03 ssDummy)
(ssadd objLineDummy11 ssDummy)
(ssadd objLineDummy12 ssDummy)
(ssadd objLineDummy13 ssDummy)
(ssadd objLineDummy14 ssDummy)

(setq ss ssDummy)
(LikeTrim ss )

 

(defun LikeTrim ( ss)
(if ss
(progn
(sssetfirst nil nil)
(command-s "_.-BOUNDARY")
(command "_.erase" ssDummy "")
)
))

0 Likes
Message 7 of 14

dbhunia
Advisor
Advisor

first thing "objLineDummy*" must be "Entity name"..... like.....

 

(defun c:ss1 ()
(setq ssDummy(ssadd))
(ssadd (setq objLineDummy1 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy2 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy3 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy11 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy12 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy13 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy14 (car(entsel))) ssDummy)
(ssadd (setq objLineDummy15 (car(entsel))) ssDummy)
(setq ss ssDummy)
(LikeTrim ss)
)
(defun LikeTrim ( ss)
(if ss
   (progn
	;(sssetfirst nil nil)
	(command-s "_.-BOUNDARY")
	(command "_.erase" ss "")
   )
)
)

 

Use "SS1" as a command you can understand......(This is only for the attached Drawing & as per your attached image)

 

Here "(setq objLineDummy* (car(entsel)))" is used only to get the "Entity name"...........

 

If your variables "objLineDummy*" containing "Entity name"........... then the syntax will be like.......

 

(ssadd objLineDummy* ssDummy)

instead of ......

(setq objLineDummy* (car(entsel)))

 

But if your requirement is as per your attached image .......... then I think the solution of @ВeekeeCZ is best fit for you....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 8 of 14

ВeekeeCZ
Consultant
Consultant

How do you (want to) get all the objLineDummy** entities/objects? 

Did you create them, over exporte them, you will select them? All at one / one by one...

0 Likes
Message 9 of 14

Anonymous
Not applicable

Hi BeeKee CZ

 

I've listed all of the obj i want to select, and it worked.

 

however, i don't know how to make " mouse click 3 times" in the code.

(as your video strat from 0:06)

https://knowledge.autodesk.com/community/screencast/c8d61d55-64b3-485c-9abc-b056d4931998

 

Thank you.

0 Likes
Message 10 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Anonymous wrote:

... however, i don't know how to make " mouse click 3 times" in the code....

 

--

Well, and how do you want to get those point? User Pick? Or calculated? The pick is quite simple. Just add as many PAUSE as you need:

(command "boundary" ss "" pause pause pause)

 

But if the later, that would be challenging for you. And impossible for me to answer - since you never answer any of my questions. So, just think about it, how would you calculate some inside points from entities you have - you don't need to be a programmer, it's just a geometry. If you tell me the algorithms, you'll help you to put it in the code.

0 Likes
Message 11 of 14

Anonymous
Not applicable

@ВeekeeCZ

 

Thank you for the reply always, it really helps me a lot.

Sorry for i didn't explained clearly.

 

On this project, I have to draw pattern array in a specify rectangle area.

concept.jpgpattern.jpg

 

How do you (want to) get all the objLineDummy** entities/objects? 

Did you create them, over exporte them, you will select them? All at one / one by one...

>> i create them first then i will put them to the right place, and the last step is using array to copy them.

 

But if the later, that would be challenging for you. And impossible for me to answer - since you never answer any of my questions. So, just think about it, how would you calculate some inside points from entities you have - you don't need to be a programmer, it's just a geometry. If you tell me the algorithms, you'll help you to put it in the code.

>> since it required 3 click point after using your solution, i calculated 3 point as below.

 

pt1.x = (A-B)/2

pt1.y = (L-2C)*1/4

 

pt2.x = (A-B)/2

pt2.y = (L-2C)*2/4

 

pt3.x = (A-B)/2

pt3.y = (L-2C)*3/4

 

for other lines and point, it's calculated by tan/sin/cos and polar in the code' first step as attachment.

 

 

pt123.jpg

 

Last but not the least, I still don't know how to automatically finish the last step of your solution.

I have to click pt1, pt2, pt3 by mouse then press "SPACE" by keyboard, then your solution worked perfectly.

(but I need it to be done automatically)

problem.jpg

(defun LikeTrim (ss pt1 pt2 pt3)
(if ss
(progn
(sssetfirst nil nil)
(command-s "_.-BOUNDARY")
(command "erase" ss "" pt1 pt2 pt3 pause)

)
)
)

 

Message 12 of 14

Anonymous
Not applicable

Update lsp file again.~

0 Likes
Message 13 of 14

Anonymous
Not applicable

@ВeekeeCZ

 

Successed !!!

 

modified the code as below.

 

(defun LikeTrim (ss pt1 pt2 pt3)
(if ss
(progn

(sssetfirst nil nil)
(command-s "_.-BOUNDARY" pt1 "")
(command-s "_.-BOUNDARY" pt2 "")
(command-s "_.-BOUNDARY" pt3 "")
(command "erase" ss "")

);progn
);if
);defun

 

Thank you so much. 

Message 14 of 14

ВeekeeCZ
Consultant
Consultant

Glad that you figured it out on your own!

BTW These things are sensitive about to be on the visible screen. Consider to ZOOM Extents before you run it.