See the top rated post in this thread. Click here

Results 1 to 8 of 8

Thread: Inserting Dynamic Blocks along the points of Polyline using LISP

  1. #1
    Member
    Join Date
    2017-10
    Posts
    15
    Login to Give a bone
    0

    Exclamation Inserting Dynamic Blocks along the points of Polyline using LISP

    Hi, I want a LISP routine which can insert blocks along the polyline.
    I have two dynamic blocks. They are 'Straight Duct' and 'Elbow90'. Consider I draw a polyline with three XY coordinates i.e. (1,1) , (1,2) and (2,2) and insert rectangular block with desired 'Width'. Here are list of things I want from LISP program:
    1. I want 'Straight Duct' to be inserted at mid-points of '(1,1) & (1,2)' and '(1,2) & (2,2)'.
    2. Also, those inserted blocks should be rotated with an angle made by those points with horizontal so that 'Straight Duct' remains along the line. Example, Angle made by line joining points '(1,1) & (1,2)' with horizontal is 90 Deg. Hence, Dynamic Block should be rotated by 90 degree about midpoint.
    3. Move the grip of 'Straight Duct' (which facing to open end of polyline) to the open end of polyline. Move other grip of 'Straight Duct' to the length of (150+ Width/2) mm less than the intersection point.
    4. Insert 'Elbow90' at the point with polar angle 45 Degree to point of intersection and polar radius (150 + Width/2) mm. Also, the grip of elbow should be moved so that width of 'Elbow90' should be as same as that of 'Straight Duct'.

    Pls refer the attached file for understanding the problem.
    Can anyone help me out?
    Attached Files Attached Files

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    0

    Default Re: Inserting Dynamic Blocks along the points of Polyline using LISP

    Have you any code to share with others? Other members may have code they may be willing to share to help you get started.

    Do you need somewhere to start? You might try searching the forums. I found this which may meet some of your request.

    Or are you looking for a ready made routine? For me, your request does not fit my field of work. I can't help you.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Member
    Join Date
    2015-09
    Posts
    5
    Login to Give a bone
    0

    Default Re: Inserting Dynamic Blocks along the points of Polyline using LISP

    Quote Originally Posted by sbmunde View Post
    Hi, I want a LISP routine which can insert blocks along the polyline.
    I have two dynamic blocks. They are 'Straight Duct' and 'Elbow90'. Consider I draw a polyline with three XY coordinates i.e. (1,1) , (1,2) and (2,2) and insert rectangular block with desired 'Width'. Here are list of things I want from LISP program:
    1. I want 'Straight Duct' to be inserted at mid-points of '(1,1) & (1,2)' and '(1,2) & (2,2)'.
    2. Also, those inserted blocks should be rotated with an angle made by those points with horizontal so that 'Straight Duct' remains along the line. Example, Angle made by line joining points '(1,1) & (1,2)' with horizontal is 90 Deg. Hence, Dynamic Block should be rotated by 90 degree about midpoint.
    3. Move the grip of 'Straight Duct' (which facing to open end of polyline) to the open end of polyline. Move other grip of 'Straight Duct' to the length of (150+ Width/2) mm less than the intersection point.
    4. Insert 'Elbow90' at the point with polar angle 45 Degree to point of intersection and polar radius (150 + Width/2) mm. Also, the grip of elbow should be moved so that width of 'Elbow90' should be as same as that of 'Straight Duct'.

    Pls refer the attached file for understanding the problem.
    Can anyone help me out?
    Here you can find somthing useful
    https://autolispprograms.wordpress.c...c-application/

  4. #4
    Member
    Join Date
    2017-10
    Posts
    15
    Login to Give a bone
    0

    Unhappy Re: Inserting Dynamic Blocks along the points of Polyline using LISP

    Here is the code I am working on:
    This code insert "Straight Duct" block at required points and with required rotation.
    But I am not able to insert "Elbow90" (Don't Know Why?). But I am working on it.

    I want to know if I can move grips of that dynamic blocks to required points.
    Can you help me?

    Code:
    (vl-load-com); if needed
    
    (defun C:PtoDB (/ plent plobj coords num pt)
      (setq
        plent (car (entsel "\nSelect Polyline: "))
        plobj (vlax-ename->vla-object plent)
        coords (vlax-get plobj 'Coordinates); un-differentiated list of X Y [& Z if applicable] coordinate values
      ); setq
      (setq num (if (= (cdr (assoc 0 (entget plent))) "LWPOLYLINE") 2 3))
    
        ; LW Polylines have only X & Y; "heavy" 2D & 3D have X Y & Z
      (repeat (/ (length coords) num)
        (repeat num ; number of coordinates to separate into a point list
          (setq
            pt (append pt (list (car coords)))
            coords (cdr coords)
          )
        ); repeat
      ); repeat
      (setq pt (reverse pt)); list of coordinates divided up into point lists
    
      (setq width (getint "Enter the width of duct:"))
       
      (setq p1 (list (nth 1 pt) (nth 0 pt) 0))
      (setq p2 (list (nth 3 pt) (nth 2 pt) 0))
      (setq p3 (list (nth 5 pt) (nth 4 pt) 0))
      (setq ang1 (angtos (angle p1 p2)))  
      (setq ang2 (angtos (angle p2 p3)))
      (setq diff (+ 150 (/ width 2)))
      ;(princ diff)
    
      (cond ((and (and (> (cadr p2) (cadr p1)) (= (cadr p2) (cadr p3))) (and (= (car p2) (car p1)) (> (car p2) (car p3))))
    	(setq ang3 (itoa 0))
    	(setq p4 (list (- (car p2) diff) (- (cadr p2) diff) 0))
    	)
      	((and (and (> (cadr p2) (cadr p1)) (= (cadr p2) (cadr p3))) (and (= (car p2) (car p1)) (< (car p2) (car p3))))
    	(setq ang3 (itoa 90))
    	(setq p4 (list (+ (car p2) diff) (- (cadr p2) diff) 0))
    	)
    	((and (and (= (cadr p2) (cadr p1)) (< (cadr p2) (cadr p3))) (and (< (car p2) (car p1)) (= (car p2) (car p3))))
    	(setq ang3 (itoa 180))
    	(setq p4 (list (+ (car p2) diff) (+ (cadr p2) diff) 0))
    	)
    	((and (and (= (cadr p2) (cadr p1)) (< (cadr p2) (cadr p3))) (and (> (car p2) (car p1)) (= (car p2) (car p3))))
    	(setq ang3 (itoa 270))
    	(setq p4 (list (- (car p2) diff) (+ (cadr p2) diff) 0))
    	)
      )
    
      (command "_Insert" "Straight Duct" "_mtp" p1 p2 1 "" ang1)
      (command "_Insert" "Straight Duct" "_mtp" p2 p3 1 "" ang2)
      ;(command "_line" p2 p4 "")
      (command "_Insert" "Elbow90" p4 1 1 ang3)
    ); defun

  5. #5
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Inserting Dynamic Blocks along the points of Polyline using LISP


  6. #6
    Member
    Join Date
    2017-10
    Posts
    15
    Login to Give a bone
    0

    Default Re: Inserting Dynamic Blocks along the points of Polyline using LISP

    Thank you Responses. I have arrived near to the end of my program. The program can insert blocks with changing parameters & attributes to required value. But, the block "Elbow" is not inserted at required point. I couldn't find the reason behind that. Can anyone please help me to find the error. The block "Ebow90" should be inserted at point 'P4'.

    Pls find attached files to understand the problem.
    Attached Files Attached Files

  7. #7
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,105
    Login to Give a bone
    1

    Default Re: Inserting Dynamic Blocks along the points of Polyline using LISP

    After you execute the routine, is P4 set to the expected coordinates? Are you using running osnaps? If one or both of these are true, you might place a "non" osnap declaration prior to providing the P4 coordinate to the Insert command.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #8
    Member
    Join Date
    2017-10
    Posts
    15
    Login to Give a bone
    0

    Default Re: Inserting Dynamic Blocks along the points of Polyline using LISP

    Thanx Opie. I forget to turn off the Osnap
    I have added below lines:


    Code:
      (setq os (getvar 'osmode))
      (setvar 'osmode 0)
      ;CODE HERE
      (setvar 'osmode os)

    Now, it runs fine.
    Thank you all.

Similar Threads

  1. Inserting blocks in table cells using LISP
    By costas.vassiliou in forum AutoLISP
    Replies: 26
    Last Post: 2018-11-29, 08:51 PM
  2. Inserting dynamic blocks into table?
    By jzampardi in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2010-05-14, 06:42 PM
  3. Polyline Thickness in Dynamic Blocks
    By CADdancer in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2009-10-28, 05:18 PM
  4. Replies: 4
    Last Post: 2007-04-29, 11:51 AM
  5. Lisp code when inserting blocks from tool palettes
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2006-06-02, 12:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •