Author Topic: SOLVED_selecting previous object after subssequent commands & Join command  (Read 2551 times)

0 Members and 1 Guest are viewing this topic.

Windsor

  • Mosquito
  • Posts: 14
Hi there,

Hopefully someone can shine a bit of light on what I'm doing wrong here.

I want to rotate a 3dpolyline about an already specified UCS, the commands in the attached .lsp file work but needing to select the line again each time, I tried using (command "PSelect" "P" "") , but this does not work for me.
Is there a more elegant solution to this?

And also cant figure out how to get the join command to join the lines back to gether properly.

I'm probably overlooking something quite simple but cant figure it out.

Any help with these would be greatly appreciated.

Code: [Select]
(defun c:FLIP()

(command "Rotate3D" (setq ss1 (ssget)) "" "0,0,0" "1,0,0" "" "270")
(command "Explode" (setq ss1 (ssget)) "")
(command "change" (setq ss1 (ssget)) "" "P" "E" "0" "")
(command "Join" (setq ss1 (ssget)) "")

(princ)

)
« Last Edit: November 16, 2022, 06:09:27 AM by Windsor »

nekonihonjin

  • Newt
  • Posts: 103
Re: selecting previous object after subssequent commands & Join command
« Reply #1 on: November 12, 2022, 11:30:06 AM »
Not sure if you want to select one 3dpoly or many of them, this is for just one, then select the UCS line to use for rotate:

Code: [Select]
(defun c:test ( / )
(vl-load-com)
(setq line (entsel "\nSelect 3dpolyline: ")
      ucl  (car (entsel "\n Select UCS LINE: "))
      uclv (vlax-ename->vla-object ucl)
      pt1  (vlax-curve-getStartPoint uclv)
      pt2  (vlax-curve-getEndPoint uclv))
(command "_.rotate3d" line "" pt1 pt2 "270")
(command "_.explode" line "")
(initcommandversion)(command "_.join" "p" "")
(command "_.change" (entlast) "" "P" "E" "0" "")       
(princ)
)

about the JOIN command not working properly:
https://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-6176FC98-DC5D-433E-8D76-F481BE68D46A
« Last Edit: November 12, 2022, 05:05:17 PM by nekonihonjin »

Windsor

  • Mosquito
  • Posts: 14
Re: selecting previous object after subssequent commands & Join command
« Reply #2 on: November 14, 2022, 04:57:37 AM »
Hi nekonihonjin,

The routine you sent on works like a dream.

Only thing is it works when the co-ordinate system us in WCS.
Is there any way to incorperate changing the UCS to world and then back to previous when the routine is complete?
My Lisp skills arent advanced enough to incorperate this, I tried to add in (command "ucs" "w") at the beginning but this didnt appear to work.

Would appreciate help incorperating this.

nekonihonjin

  • Newt
  • Posts: 103
Re: selecting previous object after subssequent commands & Join command
« Reply #3 on: November 14, 2022, 09:50:51 AM »
Hi nekonihonjin,

The routine you sent on works like a dream.

Only thing is it works when the co-ordinate system us in WCS.
Is there any way to incorperate changing the UCS to world and then back to previous when the routine is complete?
My Lisp skills arent advanced enough to incorperate this, I tried to add in (command "ucs" "w") at the beginning but this didnt appear to work.

Would appreciate help incorperating this.

like this:?

Code: [Select]
(defun c:test ( / *error* line ucl)
(vl-load-com)
  (defun *error* ( msg )
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " msg))
    ); if
    (command-s "_.ucs" "_restore" "TempUCS")
    (command-s "_.ucs" "_delete" "TempUCS")
    (princ)
  ); defun - *error*
(setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (tblsearch "ucs" "TempUCS")
    (vla-delete (vla-item (vla-get-usercoordinatesystems AcDoc) "TempUCS"))
);if
(command "_.ucs" "_save" "TempUCS")
(setq line (entsel "\nSelect 3dpolyline: ")
      ucl  (car (entsel "\n Select UCS LINE: "))
      uclv (vlax-ename->vla-object ucl)
      pt1  (vlax-curve-getStartPoint uclv)
      pt2  (vlax-curve-getEndPoint uclv)
      y    -1)
(command "_.ucs" "")
(command "_.rotate3d" line "" pt1 pt2 "270")
(command "_.explode" line "")
(initcommandversion)(command "_.join" "p" "")
(command "_.change" (entlast) "" "P" "E" "0" "") 
(command "_.ucs" "_restore" "TempUCS" "_.ucs" "_delete" "TempUCS")     
(princ)
)

done using the data & tips provided on this post:
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/ucs-save-and-restore/td-p/1939412



Windsor

  • Mosquito
  • Posts: 14
Re: selecting previous object after subssequent commands & Join command
« Reply #4 on: November 16, 2022, 06:08:07 AM »
That's exactly what is required, thank you very much for helping out with this issue!

nekonihonjin

  • Newt
  • Posts: 103
Re: selecting previous object after subssequent commands & Join command
« Reply #5 on: November 16, 2022, 09:49:57 AM »
That's exactly what is required, thank you very much for helping out with this issue!

I'm sure any of the advanced members can make a more elegant and functional way. But I'm glad you find it useful.

mhupp

  • Bull Frog
  • Posts: 250
Re: SOLVED_selecting previous object after subssequent commands & Join command
« Reply #6 on: November 16, 2022, 02:29:29 PM »
Another way if you have more then one entity being generated is to set a point in the drawing database with the following.

Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssadd)) ;need a blank selection set or exiting one to add entity's to
  2. (setq LastEnt (entlast)) ;sets the start point for anything created/modified after this will be added to the selection set
  3. (if (setq en (entnext LastEnt))
  4.   (while en
  5.     (ssadd en ss) ;steps thought the drawing from LastEnt to the end adding entity's the the selection set.
  6.     (setq en (entnext en))
  7.   )
  8. )
  9. (sssetfirst nil ss) ;highlight selection set
  10. ;or use it in a command
  11. (command "_.Erase" ss "")