Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Teaser for all Experts

5 REPLIES 5
Reply
Message 1 of 6
rodb
355 Views, 5 Replies

Teaser for all Experts

The problem
I have blocks on a grid. I'd like to label the blocks from their insert point with a dimension from the nearest gridline on the left and the nearest gridline from the top. The gridlines all have a code at the end of each line. So the label would read 33H-167 T4-190 as in the example dwg. 167 would be the distance rounded off to an integer in millimeters from the Grid line 33H on the left (-X direction) and 190 would be the distance from Grid line T4 (+Y direction).

Would it be possible to have a program that went to each block inserted on the following layers
AQ_LIGHTING_ART
AQ_LIGHTING_EMERGENCY
AQ_LIGHTING_HIGH_LEVEL
AQ_LIGHTING_LOW_LEVEL
AQ_LIGHTING_VERTICAL

and measured the distances above and wrote the text using the AQ_CIRCUIT text style directly under the block on the AQ HIGH LEVEL GRID TEXT layer if the block was inserted on the AQ_LIGHTING_HIGH_LEVEL layer and on the AQ LOW LEVEL GRID TEXT layer if the block was inserted on any of the rest of the layers above.

Plus insert a block HIGH LEVEL MARK on the insert point of each block on the AQ_LIGHTING_HIGH_LEVEL layer onto the AQ HIGH LEVEL INSERT MARK layer and a block LOW LEVEL MARK on the insert point of each block on the rest of the layers above on the AQ LOW LEVEL INSERT MARK.

I'm not sure how to look for the nearest gridline on the left and pick up its code (33H) Maybe make them all into blocks called 33H,33G etc and pick up the block name or make them polylines with entity data. I have never dealt with entity data though.

Then you have to measure the distance to that line on the left using a perpendicular snap, round it off add the 33H prefix and do that with the vertical distance then create the 33H-167 T4-190 text under the block.

Does anyone have any idea how to do this??? It would be such a help as dimension lines would be so difficult to read and extremely cluttered when the blocks are close together.

5 REPLIES 5
Message 2 of 6
rodb
in reply to: rodb

Just had a thought if you find the nearest vertical gridline to the left and go to the endpoint then take the x value and subtract it from the x value of the insertion point of the block you have the distance from it, ditto with the nearest horizontal gridline above's Y value. So you don't need to do a distance to the gridlines from the insert point. Now how to make sure you go left or up to pick up the gridline and what is the best way to find its name? make them into blocks or use entity data? 

Message 3 of 6
rodb
in reply to: rodb

And I have just realised although I can freeze all the layers except the blocks and gridlines I want there are lines that have been blocked on these layers

AQ_LIGHTING_ART
AQ_LIGHTING_EMERGENCY
AQ_LIGHTING_HIGH_LEVEL
AQ_LIGHTING_LOW_LEVEL
AQ_LIGHTING_VERTICAL

 

So I cannot freeze them. So the search for the gridlines has to ignore all other entities that are not on the same layer as the grid.

 

This is really doing my head in, I can feel a brain freeze coming on!

Message 4 of 6
rodb
in reply to: rodb

Well I have a program working manually in that you have to select the fitting and the left grid line and the top gridline. If only it could be made to select those grid lines instead of me having to do so it work all by itself..... and I could go make a cup of coffee! I still have to tidy the whole program now though

 

;copyright Rod Borland, London 2014
;Dimension fittings from grid lines
(defun restore ()                     ;restore variables
      (command "layer" "set" cly "")
      (setvar "cmdecho" cmd)
      (setvar "osmode" osm)
      (setvar "expert" etp)
      (setq *error* olderr)
      (print)
)
(defun trap (er)                       ;error trapping
      (print "\nPROGRAM ABORTED ")
      (print er)
      (command "layer" "set" cly "")
      (setvar "cmdecho" cmd)
      (setvar "osmode" osm)
      (setvar "expert" etp)
      (setq *error* olderr)
      (print)
)

(defun c:dimgrid ()
    (graphscr)
    ;Check and create layers
    (setq ln (tblsearch "layer" "AQ HIGH LEVEL GRID TEXT"))   ;check for layer & make it
             (if (= ln nil)
                 (command "layer" "M" "AQ HIGH LEVEL GRID TEXT" "C" "MAGENTA" "" "")
             )
      (command "layer" "ON" "AQ HIGH LEVEL GRID TEXT" "THAW" "AQ HIGH LEVEL GRID TEXT" "")
    
    (setq ln (tblsearch "layer" "AQ LOW LEVEL GRID TEXT"))   ;check for layer & make it
             (if (= ln nil)
                 (command "layer" "M" "AQ LOW LEVEL GRID TEXT" "C" "BLUE" "" "")
             )
      (command "layer" "ON" "AQ LOW LEVEL GRID TEXT" "THAW" "AQ LOW LEVEL GRID TEXT" "")
    
    (setq ln (tblsearch "layer" "AQ HIGH LEVEL INSERT MARK"))   ;check for layer & make it
             (if (= ln nil)
                 (command "layer" "M" "AQ HIGH LEVEL INSERT MARK" "C" "MAGENTA" "" "")
             )
      (command "layer" "ON" "AQ HIGH LEVEL INSERT MARK" "THAW" "AQ HIGH LEVEL INSERT MARK" "")
    
    (setq ln (tblsearch "layer" "AQ LOW LEVEL INSERT MARK"))   ;check for layer & make it
             (if (= ln nil)
                 (command "layer" "M" "AQ LOW LEVEL INSERT MARK" "C" "MAGENTA" "" "")
             )
      (command "layer" "ON" "AQ LOW LEVEL INSERT MARK" "THAW" "AQ LOW LEVEL INSERT MARK" "")

    ;get x and y coords of insert point of Fitting
    (prompt "\nSelect fitting")
    (setq fit (ssget))
    (setq name (ssname fit 0))
    (setq xfit (cdr (assoc 10 (entget name))))
    (setq xf (car xfit))
    (print xf)
    (setq yfit (caddr (assoc 10 (entget name))))
    (print yfit)
    (setq layr (cdr (assoc 8 (entget name))))
    
    ;get x coord of left grid line and its ID from block name
    (prompt "\nSelect left hand Grid Line")
    (setq left (ssget))
        (setq name (ssname left 0))
        (setq lname (cdr (assoc 2 (entget name))))
          (print lname)
        (setq xleft (cdr (assoc 10 (entget name))))
        (setq xl (car xleft))
          (print xl)
    
    ;get y coord of top grid line and its ID from block name
    (prompt "\nSelect Top Grid Line")
    (setq top (ssget))
            (setq name (ssname top 0))
            (setq tname (cdr (assoc 2 (entget name))))
              (print tname)
            (setq ytop (caddr (assoc 10 (entget name))))
            (print ytop)
    
    ;subtract Fitting coords from grid lines and compile dimension
    (setq left (- xf xl))
    (setq top (- ytop yfit))
    (setq left (rtos left 2 0))
    (setq top (rtos top 2 0))
    (setq dim (strcat lname left "-" tname top))
    (print dim)
    
    ;prepare dimension insert position and place below Fitting
    (setq xdim xf)
    (setq ydim (- yfit 100))
    (setq dimpos (list xdim ydim))
    (if (equal layr "AQ_LIGHTING_HIGH_LEVEL")
        (progn
            (command "Layer" "S" "AQ HIGH LEVEL GRID TEXT" "")
            (command "text" "j" "TC" dimpos 100 0 dim)
        )
        (progn
            (command "Layer" "S" "AQ LOW LEVEL GRID TEXT" "")
            (command "text" "j" "TC" dimpos 100 0 dim)
        )
    )
    
    ;Mark the Fitting's insert point for reference
    (setq mark (list xf yfit))
    (if (equal layr "AQ_LIGHTING_HIGH_LEVEL")
            (progn
                (command "Layer" "S" "AQ HIGH LEVEL INSERT MARK" "")
                (command "-insert" "HIGH LEVEL MARK" mark "" "" "")
            )
            (progn
                (command "Layer" "S" "AQ LOW LEVEL INSERT MARK" "")
                (command "-insert" "LOW LEVEL MARK" mark "" "" "")
            )
    )
)

Message 5 of 6
rodb
in reply to: rodb

So I have tidied the program now but its still manual, I have to pick the fitting then pick the left gridline then pick the top gridline to extract the block name and x and y coordinates. Is there any way of automating it. That would need to be able to pick the nearest gridlines to the left and top of the fitting. So making a selection in a certain direction. I do know the maximum distance a gridline would be. oh hold on a minute I can make a selection using two points for a fence I think and if there is something in the way maybe exclude that by filtering out everything that is not on the gridline layer.  

Message 6 of 6
rodb
in reply to: rodb

Sorry for being an idiot, of course ssget pt pt will do it if I can add a filter for layer.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost