Jump to content

Matchline automation


smitaranjan

Recommended Posts

Is there any chance of matchline automation using lisp in layout? I have attached sample dwg and screenshot of block for matchline. Please help. And thanks in advance. 

MATCHLINE.png

SRS.dwg

Link to comment
Share on other sites

Try this, see if you like it.

 

The code will go over all the numeric layouts.

For each layout it will ask you an insert point and angle, for 2 blocks, the previous and next... then press enter to go to the next page.

If you think this is useful, I can make it a bit more user friendly, feel free to suggest features .

 

Command MLA

 

(vl-load-com)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	https://www.lee-mac.com/attributefunctions.html

;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.
(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun drawInsert (pt Nme rot)
 (entmakex (list (cons 0 "INSERT")
                 (cons 2 Nme)
                 (cons 50 rot)
                 (cons 10 pt)))
)


	
(defun c:mla	( / layouts lyt blk ip val)
	(setq layouts (list))
    ;; Obtain list of layout objects
    (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
		;; skip layouts that don't have a numeric layout name
		(if (> (atoi (vla-get-name lyt)) 0)
			(progn
				(setq layouts (append layouts (list (vla-get-name lyt))))
			)
		)
    )
	(setq i 0)
	(foreach lyt layouts
		;; set layout as current
		(setvar "CLAYOUT" lyt)
		(if (> i 0)	(progn
			(setq val (nth (- i 1) layouts))
			(princ (strcat
				"\nPrevious Layout, "
				val
				": "
			))
			(setq blk (drawInsert (setq ip (getpoint "\nInsert point: ")) "match_line" (getangle ip "\nAngle: ")))
			(command "attsync" "_name" "match_line")
			(LM:vl-setattributevalue (vlax-ename->vla-object blk) "XX" val)
		))
		(if (nth (+ i 1) layouts) 	(progn
			(setq val (nth (+ i 1) layouts))
			(princ (strcat
				"\nNext Layout, "
				val
				": "
			))
			(setq blk (drawInsert (setq ip (getpoint "\nInsert point: ")) "match_line2" (getangle ip "\nAngle: ")))
			(command "attsync" "_name" "match_line2")
			(LM:vl-setattributevalue (vlax-ename->vla-object blk) "XX" val)
		))
		
		(getstring "\nPress enter: ")
		
		(setq i (+ i 1))
	)

)

 

Link to comment
Share on other sites

39 minutes ago, Emmanuel Delay said:

Try this, see if you like it.

 

The code will go over all the numeric layouts.

For each layout it will ask you an insert point and angle, for 2 blocks, the previous and next... then press enter to go to the next page.

If you think this is useful, I can make it a bit more user friendly, feel free to suggest features .

 

Command MLA

 

(vl-load-com)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	https://www.lee-mac.com/attributefunctions.html

;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.
(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun drawInsert (pt Nme rot)
 (entmakex (list (cons 0 "INSERT")
                 (cons 2 Nme)
                 (cons 50 rot)
                 (cons 10 pt)))
)


	
(defun c:mla	( / layouts lyt blk ip val)
	(setq layouts (list))
    ;; Obtain list of layout objects
    (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
		;; skip layouts that don't have a numeric layout name
		(if (> (atoi (vla-get-name lyt)) 0)
			(progn
				(setq layouts (append layouts (list (vla-get-name lyt))))
			)
		)
    )
	(setq i 0)
	(foreach lyt layouts
		;; set layout as current
		(setvar "CLAYOUT" lyt)
		(if (> i 0)	(progn
			(setq val (nth (- i 1) layouts))
			(princ (strcat
				"\nPrevious Layout, "
				val
				": "
			))
			(setq blk (drawInsert (setq ip (getpoint "\nInsert point: ")) "match_line" (getangle ip "\nAngle: ")))
			(command "attsync" "_name" "match_line")
			(LM:vl-setattributevalue (vlax-ename->vla-object blk) "XX" val)
		))
		(if (nth (+ i 1) layouts) 	(progn
			(setq val (nth (+ i 1) layouts))
			(princ (strcat
				"\nNext Layout, "
				val
				": "
			))
			(setq blk (drawInsert (setq ip (getpoint "\nInsert point: ")) "match_line2" (getangle ip "\nAngle: ")))
			(command "attsync" "_name" "match_line2")
			(LM:vl-setattributevalue (vlax-ename->vla-object blk) "XX" val)
		))
		
		(getstring "\nPress enter: ")
		
		(setq i (+ i 1))
	)

)

 

Sure, will check it and let you know

Link to comment
Share on other sites

6 hours ago, Emmanuel Delay said:

Try this, see if you like it.

 

The code will go over all the numeric layouts.

For each layout it will ask you an insert point and angle, for 2 blocks, the previous and next... then press enter to go to the next page.

If you think this is useful, I can make it a bit more user friendly, feel free to suggest features .

 

Command MLA

 

(vl-load-com)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	https://www.lee-mac.com/attributefunctions.html

;; Set Attribute Value  -  Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.
(defun LM:vl-setattributevalue ( blk tag val )
    (setq tag (strcase tag))
    (vl-some
       '(lambda ( att )
            (if (= tag (strcase (vla-get-tagstring att)))
                (progn (vla-put-textstring att val) val)
            )
        )
        (vlax-invoke blk 'getattributes)
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun drawInsert (pt Nme rot)
 (entmakex (list (cons 0 "INSERT")
                 (cons 2 Nme)
                 (cons 50 rot)
                 (cons 10 pt)))
)


	
(defun c:mla	( / layouts lyt blk ip val)
	(setq layouts (list))
    ;; Obtain list of layout objects
    (vlax-for lyt (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
		;; skip layouts that don't have a numeric layout name
		(if (> (atoi (vla-get-name lyt)) 0)
			(progn
				(setq layouts (append layouts (list (vla-get-name lyt))))
			)
		)
    )
	(setq i 0)
	(foreach lyt layouts
		;; set layout as current
		(setvar "CLAYOUT" lyt)
		(if (> i 0)	(progn
			(setq val (nth (- i 1) layouts))
			(princ (strcat
				"\nPrevious Layout, "
				val
				": "
			))
			(setq blk (drawInsert (setq ip (getpoint "\nInsert point: ")) "match_line" (getangle ip "\nAngle: ")))
			(command "attsync" "_name" "match_line")
			(LM:vl-setattributevalue (vlax-ename->vla-object blk) "XX" val)
		))
		(if (nth (+ i 1) layouts) 	(progn
			(setq val (nth (+ i 1) layouts))
			(princ (strcat
				"\nNext Layout, "
				val
				": "
			))
			(setq blk (drawInsert (setq ip (getpoint "\nInsert point: ")) "match_line2" (getangle ip "\nAngle: ")))
			(command "attsync" "_name" "match_line2")
			(LM:vl-setattributevalue (vlax-ename->vla-object blk) "XX" val)
		))
		
		(getstring "\nPress enter: ")
		
		(setq i (+ i 1))
	)

)

 

Don't know its working or not, by entering MLA its going to first page and ask angle. Its not working in other print. and its placing next print, as mostly in the dwg, the page are not in order

Link to comment
Share on other sites

 

This task is on a client list I have but a low priority, as I have spent a lot of time automating making layouts it could be something that can be added as part of the procedure. In the process a layout is represented as a rectang so could do a left and right next. For grid style sheets a bit harder as you can have 4 sides touching. I think it was one of your dwg's that I did the grid style layout code. Auto making the layouts.

 

A quick check of the dwg and you need to overlap the rectangs a bit more as you have gaps in your layouts. 

 

Maybe click next or prior number then select an edge and it will label in model space, may be a way to auto push through to layout paperspace. 

Edited by BIGAL
Link to comment
Share on other sites

12 hours ago, BIGAL said:

 

This task is on a client list I have but a low priority, as I have spent a lot of time automating making layouts it could be something that can be added as part of the procedure. In the process a layout is represented as a rectang so could do a left and right next. For grid style sheets a bit harder as you can have 4 sides touching. I think it was one of your dwg's that I did the grid style layout code. Auto making the layouts.

 

A quick check of the dwg and you need to overlap the rectangs a bit more as you have gaps in your layouts. 

 

Maybe click next or prior number then select an edge and it will label in model space, may be a way to auto push through to layout paperspace. 

Is auto matchline also can be done? Irrespective of their position of viewport...please check the dwg and the placement of matchline in layout and message me personally.  Thanks.

Link to comment
Share on other sites

To put match lines in automatically have no idea where to even start, In my walk along a pline yes could be done as you know rectang numbers and which layout is next. For random rectangs all over the place some touching some not as commented earlier. 

 

Will think about pick rectang label1, pick label2 then a side as a 1st go, remember something is better than doing it manually.

Edited by BIGAL
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...