Jump to content

Recommended Posts

Posted (edited)

Hey everyone,

Just learning more about LISP routines these days to help with my work flow at my office.

I am trying to create some siting & grading routines that work with our office standards.

I am finding that a lot of these routines will use the same selection methods.

Pick this point and use the text grade value OR pick this attributed block, use the insertion point and the attribute value or a mixture of both.

Once these values are retrieved, then a calculation must be done then return a slope % or a grade point value etc etc.

So my approach to this repeated selection method was to make a function that selects the 2 points and values then call on that function whenever I run a particular lisp...

For example interpolate:

I would run the Interpolate Lisp routine, then it would use this GetElevs to get my points and values, then it would head back to the interpolate lisp and do the math and the rest of the stuff I need it to do to calculate the point somewhere between these 2 points.

 

I am having a bit of an issue with the selection methods.

So the idea is to select the first object, check to see if its text or mtext, if true, then select the corresponding point. If false then check if it has an attribute and get that info.

Then rinse and repeat for the 2nd point.

The issue I am having seems to be with the nentsel. I used to use entsel and it work well, but it wouldn't return my pt1 or pt2 from the attributed block. I switched to nentsel, but now its not returning the attribute or text values, but it is returning the points.

 

Also, pardon the sloppy coding, if you have any thoughts on how I can improve this code, it would be much appreciated. I was thinking about using a while or repeat, but I wasnt sure how to ask for a second grade value or second grade point..... unless I use strcat and set them to a ..... I'll figure that out later.

 

Anyways, any thoughts on what I can do here? I am not sure what to do here and what either of the functions returns to figure it out.

 

And Yes I know I have a whole file full of Lee Mac functions. His code is great and I have learned a ton from his work.

 

Thanks in advance.

 

(defun c:GetElevs (/)
    (vl-load-com)
  (LeeMac)
    (setq ent1 (car (nentsel "\nSelect first grade value: ")))
	(if ;selecting the first point... is it text or a block?
	  ;STARTING FIRST CONDITION TO CHECK FOR TEXT OR MTEXT
	   (wcmatch (cdr (assoc 0 (entget ent1))) "TEXT,MTEXT");condition check then do
	   ;(setvar "OSMODE" 32)
	   (setq ent1 (car (entsel ent1))
	     	 pt1 (Getpoint "\nSelect first grade point: ")
		 pt1 (list(car pt1)(cadr pt1) 0 )
		 hgt1 (car (LM:parsenumbers (cdr (assoc 1 (entget ent1)))))
		 hgt1 (LM:UnFormat hgt1 nil)
		 hgt1 (atof hgt1)
		 )
	  ;2nd Condition
	(progn
     	(setq hgt1 (LM:getattributevalue ent1 "ELEV" )
      	      ;hgt1 (atof hgt1)
	      )
	  (and
  		(= "ATTRIB" (cdr (assoc 0 (entget ent1))))
  		(setq attobj1 (vlax-ename->vla-object ent1))
  		(setq blkobj1 (cdr (assoc 330 (entget ent1))))
  		(setq attpt1 (vlax-get attobj1 'InsertionPoint))
  		(setq blkpt1 (cdr (assoc 10 (entget blkobj1))))
		(setq pt1 (trans blkpt1 0 1))
	    )
	); and
	  ;end 2nd condition
	  );end conditional statement
  
  ;--==START SECOND POINT SELECTION==--
    (setq ent2 (car (nentsel "\nSelect second grade value: ")))
	(if ;selecting the first point... is it text or a block?
	  ;STARTING FIRST CONDITION TO CHECK FOR TEXT OR MTEXT
	   (wcmatch (cdr (assoc 0 (entget ent2))) "TEXT,MTEXT");condition check then do
	   ;(setvar "OSMODE" 32)
	   (setq pt2 (Getpoint "\nSelect first grade point: ")
		 pt2 (list(car pt2)(cadr pt2) 0 )
		 hgt2 (car (LM:parsenumbers (cdr (assoc 1 (entget ent2)))))
		 hgt2 (LM:UnFormat hgt2 nil)
		 hgt2 (atof hgt2)
		 )
	  ;2nd Condition
	(progn
     	(setq hgt2 (LM:getattributevalue ent2 "ELEV" )
	      ;hgt2 (atof hgt2)
	      )
	  (and
  		(= "ATTRIB" (cdr (assoc 0 (entget ent2))))
  		(setq attobj2 (vlax-ename->vla-object ent2))
  		(setq blkobj2 (cdr (assoc 330 (entget ent2))))
  		(setq attpt2 (vlax-get attobj2 'InsertionPoint))
  		(setq blkpt2 (cdr (assoc 10 (entget blkobj2))))
		(setq pt2 (trans blkpt2 0 1))
		
	    )
	); and
	  ;end 2nd condition
	  );end conditional statement
  
	(setq exv (trans (list 0 0 1) 1 0 T)
	      tmpln (entmake (list
				'(0 . "LINE")
			       (cons 8 "A-Slope-Frozen")
			       (cons 10 (trans pt1 1 0))
			       (cons 11
				     (trans pt2 1 0))
			       (cons 210 exv)
			       );list
		);entmakex
	      
	)
  (princ)
  )

 

Edited by Strydaris
Posted (edited)

You can use a ssget and pick just one object, then use ssname ss 0 to get that entity, the advantage is that you can use a filter of "*TEXT,INSERT" so can only be an object of that type.

 

Check out Lee-mac ssget, ssget Function Reference | Lee Mac Programming (lee-mac.com) 
http://lee-mac.com/ssget.html

(ssget "_+.:E:S" '((0 . "*TEXT,INSERT")))

 

A dwg would help. 

 

Your mixing VL and assoc maybe just use the VL methods. Getattributes comes to mind.

Edited by BIGAL
  • Like 1
Posted (edited)

Hey BIGAL,

 

Thanks for the quick reply. I've attached a dwg with the blocks and text that we get to do this siting & grading work.

Basically that code I posted works like this, select an object text, if its text or mtext then select the point. if its a block with an attribute, use that then repeat for the next point. Then it draws a temp line between the 2 points.

 

With ssget, is there a way to force just 1 selection though? People in my office arent too savvy in the ways of CAD, so I am trying to make this as dummy proof as possible.

 

As for the mixing of VL and assoc, I'm still a bit new to coding lisp especially the VL, so a lot of what I am writing right now, is from reading the forums, finding what might work for me, then looking up what those functions do in the help docs, then modifying them as I need. Its not ideal, but I'm learning. lol

GetElevs example.dwg

Edited by Strydaris
Posted

If I understand correct you have 2 scenarios, a block with a "X" marks the spot and second a text say with a "X" but no attribute elevation value. Can you confirm please. Else if always the block then easy force look for block pick.

 

image.thumb.png.b8bfbdc44b8f7e070878b9afa1c1ee5f.png

Posted

Hey Bigal,

Yes, you are correct, but technically there is 4 scenarios. Text then block, Text then text, block then text or block then block.

The idea is to be able to pick either or. Text then getpoint at X or the block and get insertion point at the X, then repeat for the second point.

 

I did post my question on the Autodesk forums and someone posted a great solution.

This code is for selecting 1 point. I have simply repeated the same code for the second point.

I was also thinking about adding a repeat to the code so I dont have to have the second portion below, but for right now, its doing exactly what I need it to do so I dont want to mess with it. I may explore that when I am more experience/knowledge.

 

Thanks for taking a look at this though BIGAL. Its guys like you that make learning this stuff enjoyable.

(defun c:getxyh ()
  
  (if (and (setq e (car (entsel "Pick elevation: ")))
	   (setq y (cdr (assoc 0 (entget e))))
	   )
    (cond ((= y "INSERT")
	   (setq p (reverse (cdr (reverse (cdr (assoc 10 (entget e))))))
	         h (atof (cdr (assoc 1 (entget (entnext e)))))))             ;; alt. (atof (getpropertyvalue e "ELEV"))
	         	  
	  ((= y "TEXT")
	   (if (setq p (getpoint "\nFirst grade point: "))
	     (setq p (reverse (Cdr (reverse p)))
		   h (atof (cdr (assoc 1 (entget e)))))))
	  
	  ((= y "MTEXT")
	   (if (setq p (getpoint "\nFirst grade point: "))
	     (setq p (reverse (cdr (reverse p)))
		   h (atof (getpropertyvalue e "Text")))))
	  
	  ))
  
  (append p (list h))
  )

 

  • Like 1
Posted

Ok still dont understand if the block with the "X" exists then just reply "missed try again Please pick the "X" much more reliable than just pick anything you like, sometimes you have to educate the end user, provide more hints when asked to pick. As suggested to me a  4x2 works wonders when suggesting to a user to read the prompts.

Posted

Hi Bigal,

So this is going to be used for siting and grading work in the residential industry.

We deal with different builders and therefore receive different files from the grading engineer.

Not all the Engineers use attributed blocks to do their point elevations. Some use the text/mtext with a block for the X.

Our old way of doing things was to use the command "Change" and set all the Z axis to 0, then burst the blocks so that everything is useful for ACAD LT.

We do have a couple PCs with full ACAD on them, but the rest are LT.

Anyways, point being is that I am trying to build a set of routines to do the mathematical functions for us rather than using an excel spread sheet and calculator.

I want the routines I create to be able to work with for any situation. Its much more useful for us that way.

I have someone testing them right now with the updated code I pasted in the earlier post and she had no problem understanding what was asked of her in the prompts.

I appreciate that help though. I am trying to understand more about how to do better lisps.

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