Jump to content

Recommended Posts

Posted

Hello,

 

I’m looking to copy and move particular components of my 3D model that I select and then rotate said components.  I’ve had great success (at times) with the lsp files I’ve written but I am unsure why I get inconsistent results and would love to get some tips.  I should declare that I’m a bit of an old time steel detailer who is new to this particular side of autoCAD but am quite keen to explore and learn a lot from it.  I say this to partly excuse why there might be some glaring mistakes/bad habits in my text.

 

The main question/problem I have is why my copy routine (copytest.lsp) will generally only work when I have my 3D model in top view.  This isn’t strictly the case but if I pan/orbit around my model or go to set isometric views (Northwest, Southeast etc) and then run routine, it will often not work.  Similarly, to rotate an object about the x axis (in world UCS), the routine (rottest.lsp) will generally only work if my view is perpendicular to the axis of rotation.  So I need to be in the ‘left’ or ‘right’ view before running routine to successfully rotate an object about the x axis.  I would have thought that changing the UCS within the routine would mean that the routine would run no matter what the current view is. Especially as the UCS does not necessarily change with a change in view.

 

Furthermore, if I try and group the copy and rotate routines together, they seem to never work correctly.  It’s not a huge issue but I seem to have to run my copy routine and rotate routines independently.

 

One concern I have is that I have set up/used too many variables of the same name while practicing building/writing routines.  Is this a concern?  Do I need to delete previously run routines to wipe out older variable names?  I’m also aware that although my routine is logical (to me anyway), it may not be the correct way to go about it.

 

Any guidance would be greatly appreciated.

 

(defun c:copytest()

  ;Routine will copy weldment from middle setout point to 1st and 3rd setout points
  ;All coordinates are with respect to world UCS

    
  (setq pt1c '(400000 400000 5000);reference coordinate to copy weldment to 
        pt2c '(420000 420000 5000);reference coordinate to copy weldment from + selection window coordinate
        pt3c '(440000 440000 5000));reference coordinate to copy weldment to + selection window coordinate
  
  (setq s1c (ssget "W" pt3c pt2c '((-4 . "<NOT") (8 . "0") (-4 . "NOT>"))));weldment selection window excluding layer '0'

  (command "copy" s1c "" pt2c pt1c);Copies weldment from pt2c to pt1c
  (command "copy" s1c "" pt2c pt3c);Copies weldment from ptc to pt3c


  (princ)

	
  )
(defun c:rottest()

  ;This routine rotates 2 weldments to assist creation of orthogonal views 

  (command "ucs" "W");Firstly check model is in world UCS so following coordinates work correctly
  
  (setq pt1r '(0 0 0);point at origin
        pt2r'(0 1000 0);arbitrary point along y axis
	pt3r '(0 0 1000));arbitrary point along z axis
  
  (command "ucs" "_3p" pt1r pt2r pt3r);Sets UCS along desired axis of rotation

  ;Set points in 'right view' UCS for selection and rotation of weldments in 1st and 3rd setout areas

  (setq pt1r '(420000 25000 420000) ;Top right corner of 1st setout area
        pt2r '(400000 5000 420000) ;Bottom left corner of 1st area
	pt3r '(410000 15000 420000) ;Middle of face of 1st area
  	pt4r '(460000 25000 460000) ;Top right corner of 3rd area
	pt5r '(440000 5000 460000) ;Bottom left corner of 3rd area
	pt6r '(450000 15000 460000)) ;Middle of face of 3rd area
  
  
  (setq s1r (ssget "W" pt1r pt2r '((-4 . "<NOT") (8 . "0") (-4 . "NOT>"))));1st setout area selection window excluding layer '0'
  (setq s2r (ssget "W" pt4r pt5r '((-4 . "<NOT") (8 . "0") (-4 . "NOT>"))));3rd setout area selection window excluding layer '0'

;Now rotate weldment in 1st setout area -90 degrees for front view
;and rotate weldment in 3rd setout area +90 degrees for top view
  
  (command "rotate" s1r "" pt3r -90 )
  (command "rotate" s2r "" pt6r 90 )

  (princ)

	
  )

 

Posted

Maybe have a look at the (trans) function. It can help you out.

Posted

Thank you for your help.  I'll look into those options.

 

Cheers.

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...