Jump to content

Copy object to middle of line or polyline


Luongshop

Recommended Posts

Hi everyone!

I have problem with my program. It run unstable.

I hope everyone helps me

 

(defun mid (p1 p2)
 (list
   (/ (+ (car p1) (car p2)) 2.0)
   (/ (+ (cadr p1) (cadr p2)) 2.0)
 )
)
;______________________________________
(defun c:test ( / ob1 ob2 d0 i j ) 
 (setq ob0 (ssget))
 (setq d0 (getpoint))
 (setq ob1 (ssget "_:L" '((0 . "LINE"))))
 ;(setq i (- (sslength ob1) 1))
(repeat (setq i (sslength ob1))
 (setq j i)
 (setq d1 (cdr (assoc 10 (entget (ssname ob1 (setq i (1- i)))))))
 (setq d2 (cdr (assoc 11 (entget (ssname ob1 (setq j (1- j)))))))
 (setq mi (mid d1 d2))
 (command ".copy" ob0 "" "m" d0 mi "")
)
(princ)
)

Edited by SLW210
Aded Code Tags.
Link to comment
Share on other sites

Please read this:

http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines

 

Regarding your issue:

Your problem is most likely caused by the 'Running Osnap' setting (OSMODE). When using command calls this setting can have an impact on the outcome of Lisp programs.

See here for a possible solution ("_non"):

http://www.cadtutor.net/forum/showthread.php?102187-Getpoint-doesn-t-allow-osnap&p=693767&viewfull=1#post693767

Link to comment
Share on other sites

You have said also you want plines so p1 p2 may not give correct mid if say your pline has more than 2 pts. I would use Vla-getpointatdist take length / 2.0 this will give mid of a line and pline.

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