HelplessIntern Posted June 9, 2016 Posted June 9, 2016 I have just started learning AutoLISP from different posts on the forums and through the reference material from Autodesk but, I am hitting an error in my lisp routine that I don't know how to fix. I am trying to right a while loop that will go through a nested list and use information in the selected list segment to find points in reference to a Polyline using the vlax-curve-* functions. Currently I am using the vlax-curve-getPointAtDist with a variable distance and using a user defined polyline from the document. My code runs up until the point I try to use the getPointAtDist line which will return the error of "unable to find ObjectID for . The way I get the polyline from the user is a (setq Var (ssget "_+.:s" '((0 . "*POLYLINE")))). I have earlier in the routine the vla-load-com to load in all of the functions of visual lisp. Can anyone help me out on what I need to do to be able to run the vlax-curve-* functions? Quote
Tharwat Posted June 9, 2016 Posted June 9, 2016 You'd better post the complete codes that you are having a trouble with. Quote
HelplessIntern Posted June 9, 2016 Author Posted June 9, 2016 Here is the code that pertains to the variables and while loop. I apologize in advance for very newbie code writing. Thank you for speedy reply. (setq Centerline (ssget "_+.:s" '((0 . "*POLYLINE")))) (setq Side nil) (setq Counter 0) (setq Offset nil) (setq Station nil) (setq StaLength nil) (setq StationKM nil) (setq StationM nil) (setq BlkName nil) (setq ZZ 0.0) (setq CLAngle nil) (setq CAngle nil) (setq Coor (list 0.0 0.0 ZZ)) (setq BaseCopy (list 0.0 0.0 ZZ)) (setq RefPt (list 0.0 0.0 ZZ)) (setq AnglePt (list 0.0 0.0 ZZ)) (while(>=(- IterationNumber Counter) 0) ;;(setq CX (+ "offset in x" and "RX")) I dont think these are useful ;;(setq CY (+ "offset in y" and "RY")) I dont think these are useful (setq Entry (nth Counter *ExcelData@)) (setq BlkName (nth 0 Entry)) (setq Side (nth 1 Entry)) (setq Station (nth 2 Entry)) (setq StaLength (strlen Station)) (setq StationKM (atoi (substr Station 1 (- StaLength 4)))) (setq StationM (atoi (substr Station (- StaLength 3)))) (setq RefPt (vlax-curve-getPointAtDist (vla-get-Objectid Centerline) (+ (* (- StationKM StartKM)1000) (- StationM StartM)))) (setq AnglePt (vlax-curve-getPointAtDist Centerline (- (+ (* (- StationKM StartKM)1000) (- StationM StartM)) 2))) (setq Offset (atof (nth 3 Entry))) (setq CLAngle (angle AnglePt RefPt)) (if(or (= Side "left") (= Side "Left") (= Side "LT") (= Side "L")) (progn (setq CAngle (+ 90 (* 180 (/ CLAngle pi))))) (progn (setq CAngle (+ 270 (* 180 (/ CLAngle pi))))) ) (setq Coor (polar RefPt CAngle Offset)) (setq BaseCopy (list ((+ (car Coor) Xdiff) (+ (cadr Coor) Ydiff) ZZ))) (command "_Copy" ObjectPoint "" BasePoint Coor) (command "_ROTATE" BaseCopy "" Coor "r" "0" CAngle) ) Quote
Tharwat Posted June 9, 2016 Posted June 9, 2016 When you use the function ssget you need to retrieve the entity name with the function ssname as follows: (ssname Centerline 0) ;; since you are using the single pick mode with ssget, I used zero since you have only one object in the selection set. You need to use the above posted codes instead of the vla-get-objectID function. SEE THIS Quote
HelplessIntern Posted June 9, 2016 Author Posted June 9, 2016 Alright, I assigned a new variable below, and called it in the vlax-curve-getPointatDist also below. I am still getting the error of no ObjectID. Do I need to somehow manipulate the Entity Name? (setq Centerline (ssget "_+.:s" '((0 . "*POLYLINE")))) (setq CLName (ssname Centerline 0)) (setq RefPt (vlax-curve-getPointAtDist CLName (+ (* (- StationKM StartKM)1000) (- StationM StartM)))) Quote
Tharwat Posted June 9, 2016 Posted June 9, 2016 Alright, I assigned a new variable below, and called it in the vlax-curve-getPointatDist also below. That is good so far. I am still getting the error of no ObjectID. Do I need to somehow manipulate the Entity Name? Are you sure that you picked the right object name which is polyline in your case or the selection is not equal to nil ? Better to add if function to check if the selection is valid then do the rest of codes. eg: (if (setq centerline (ssget "_+.:s" '((0 . "*POLYLINE")))) (....... ;; etc Quote
HelplessIntern Posted June 9, 2016 Author Posted June 9, 2016 Are you sure that you picked the right object name which is polyline in your case or the selection is not equal to nil ? Better to add if function to check if the selection is valid then do the rest of codes.eg: (if (setq centerline (ssget "_+.:s" '((0 . "*POLYLINE")))) (....... ;; etc I am fairly certain that the selection set is not nil because in AutoCAD I can "!Centerline" and it returns "" however everytime I run the command and choose the same polyline the "##" in the selection set changes. I also can "!CLName" and it returns "" and the entity name is always the same. As for the if loop, this might sound very ignorant, what could I gain from putting the if loop with the test expression above? Won't that just check to make sure there is something in the selection set? Quote
Tharwat Posted June 9, 2016 Posted June 9, 2016 Yes the if function is to get sure you have valid selection set before moving to the other lines. Can you bring a sample drawing showing what you are trying to accomplish? Quote
Lee Mac Posted June 9, 2016 Posted June 9, 2016 I would suggest following this tutorial to determine the expression at which your code is failing; when the erroneous expression has been determined, we can then assist you to correct it (if you cannot do so yourself). Quote
HelplessIntern Posted June 9, 2016 Author Posted June 9, 2016 Thank you for all of your help. I was able to get the rest of the routine working after your pointers. Quote
Recommended Posts
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.