Jump to content

Recommended Posts

Posted

I've just started with AutoLisp and have been struggling with this for a while and a still have no idea where to start.

 

I have been asked to create a routine that will shorten a poly line to the nearest multiple of a set amount based on the line type, shortening the end furthest away from where the selection was made. We need this so that a dashed line can be re-sized to have a full dash at the start and finish.

 

There are 5 set line types that this would need to apply to.

 

I would see it working as follows:

 

1) User selects a line at the end to remain unmoved

2) Autocad shortens the line so that it starts and finishes with a full dash.

3) End

 

I can use the lengthen command with the DE option (and a calculator) to do it but I don't know how to automate this.

 

Any help you give me would be greatly appreciated.

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    25

  • LtRimmer

    24

Posted

If you know the calculations, just use lengthen total and select the object.

Posted

I was hoping to use something like:

 

(command "lengthen" pause "de" ????? )

 

The calculation isn't a problem I just don't know how to get the original length and then insert the adjustment.

 

We have to do this a lot in our drawings, and it's a pain and time consuming trying to do it by eye, or calculating the adjustment.

Posted

Give this a try. You didn't give me the calculations, so you'll have to change that portion.

 

(defun c:Test (/ #Ent #Value)
 (vl-load-com)
 (and (setq #Ent (entsel "\nSelect *line: ")) [color=Red]; select object[/color]
      (vl-position (cdr (assoc 0 (entget (car #Ent)))) '("LWPOLYLINE" "LINE")) [color=Red]; verify object[/color] type
      (setq #Value (* 0.5 (vla-get-length (vlax-ename->vla-object (car #Ent))))) [color=Red]; convert to vla-object, extract length and make calculations[/color]
      (vl-cmdf "_.lengthen" "_total" #Value #Ent) [color=Red]; execute lengthen command on selected object[/color]
      (princ (strcat "\nNew Length: " (vl-princ-to-string #Value))) [color=Red]; print results to command line[/color]
 ) ;_ and
 (princ)
) ;_ defun

Posted

Alanjt,

 

Many many thanks for such a fast response, that is pretty much what i was after.

 

Just one question, the formula will have to change depending on the line type selected, so can the line type be retreived to be used in an if/true statement?

 

LtRimmer

Posted
Alanjt,

 

Many many thanks for such a fast response, that is pretty much what i was after.

 

Just one question, the formula will have to change depending on the line type selected, so can the line type be retreived to be used in an if/true statement?

 

LtRimmer

No problem. :)

See above, I updated with comments.

 

Will the linetype be set at an object or layer level?

Posted

They are set at an object, ie they are all on the same layer with the line type changed.

Posted

Try something like this:

 

(defun c:Test (/ #Ent #Obj #Length #LType #Value)
 (vl-load-com)
 (and (setq #Ent (entsel "\nSelect *line: "))
      (vl-position (cdr (assoc 0 (entget (car #Ent)))) '("LWPOLYLINE" "LINE"))
      (setq #Obj    (vlax-ename->vla-object (car #Ent))
            #Length (vla-get-length #Obj)
            #LType  (strcase (vla-get-linetype #Obj))
      ) ;_ setq
      (cond
        ;; hidden2
        ((eq #LType "HIDDEN2") (setq #Value (* 0.5 #Length)))
        ;; phantom2
        ((eq #LType "PHANTOM2") (setq #Value (+ 3 #Length)))
        ;; no match
        (T (alert "No matching Linetypes!"))
      ) ;_ cond
      (vl-cmdf "_.lengthen" "_total" #Value #Ent [color=Red]""[/color])
      (princ (strcat "\nNew Length: " (vl-princ-to-string #Value)))
 ) ;_ and
 (princ)
) ;_ defun

Posted

Now that's looking good,

 

One last issue, if you select a second line with a different line type without exiting the command it changes the length to the one for the previous line type.

Is it possible to start the function again after it has changed each line length or even just exit all together?

 

I really appreciate this I've been putting off looking at it for a long time, and all because because I opened my mouth and said there should be a way to it ;-)

Posted
Now that's looking good,

 

One last issue, if you select a second line with a different line type without exiting the command it changes the length to the one for the previous line type.

Is it possible to start the function again after it has changed each line length or even just exit all together?

 

I really appreciate this I've been putting off looking at it for a long time, and all because because I opened my mouth and said there should be a way to it ;-)

 

 

Oops, forgot a "" (code updated above).

 

Glad it's working for you.

Posted

Actually, this one will make life even easier.

 

(defun c:Test (/ #Ent #Obj #Length #LType #Value)
 (vl-load-com)
 (while (setq #Ent (entsel "\nSelect *line: "))
   (and (vl-position (cdr (assoc 0 (entget (car #Ent)))) '("LWPOLYLINE" "LINE"))
        (setq #Obj    (vlax-ename->vla-object (car #Ent))
              #Length (vla-get-length #Obj)
              #LType  (strcase (vla-get-linetype #Obj))
        ) ;_ setq
        (cond
          ;; hidden2
          ((eq #LType "HIDDEN2") (setq #Value (* 0.5 #Length)))
          ;; phantom2
          ((eq #LType "PHANTOM2") (setq #Value (+ 3 #Length)))
          ;; no match
          (T (alert "No matching Linetypes!"))
        ) ;_ cond
        (vl-cmdf "_.lengthen" "_total" #Value #Ent "")
        (princ (strcat "\nNew Length: " (vl-princ-to-string #Value)))
   ) ;_ and
 ) ;_ while
 (princ)
) ;_ defun

Posted

Again many thanks, that is exactly what I was after!

 

I was intending to do some of the work myself (honest). ;-)

Posted
Again many thanks, that is exactly what I was after!

 

I was intending to do some of the work myself (honest). ;-)

 

You're welcome. :)

 

No big deal, it was a simple routine that I basically had to write to explain. You still have to fill in all the conditions, so there's work for you too. :wink:

Posted

Alanjt,

 

I was after a bit help, I'm trying to get a variant working of what you came up with above. (which works perfectly by the way)

 

I'm trying to get it so that I can draw a poly line then have it automatically re-sized when the command ends. I have added pline to draw the line and then ssget to select the last item added to the database but I can't get it to do much of anything. I've added the code below:

 

Help :unsure:

 

 

 

 

(defun c:test ()
 (vl-load-com)
 
 (vl-cmdf "_.pline")

 (setq #Ent (ssget "_l"))

 
 (vl-position (cdr (assoc 0 (entget (car #Ent)))) '("LWPOLYLINE" "LINE"))
 (setq #Obj    (vlax-ename->vla-object (car #Ent))
       #Length (vla-get-length #Obj)
       #LType  (strcase (vla-get-linetype #Obj))
 ) ;_ setq
 (cond
 ;; 4-2
   ((eq #LType "4-2") (setq #Value (+ (* (fix (/ (- #Length 4) 6)) 6) 4)))
 ;; 1-5
   ((eq #LType "1-5") (setq #Value (+ (* (fix (/ (- #Length 1) 6)) 6) 1)))
 ;; no match
   (T (alert "No matching Linetypes!"))
 ) ;_ cond
 (vl-cmdf "_.lengthen" "_total" #Value #Ent "")
 (princ (strcat "\nNew Length: " (vl-princ-to-string #Value)))
)

Posted

Quick and dirty, but try this:

(defun c:test (/ #Entlast #Ent #Obj #Length #LType #Value)
 (vl-load-com)

 (or (setq #Entlast (entlast)) (setq #Entlast T))

 (vl-cmdf "_.pline")
 (while (not (zerop (getvar 'cmdactive)))
   (princ "\nSpecify next point: ")
   (vl-cmdf PAUSE)
 ) ;_ while

 (cond
   ((not (eq #Entlast (setq #Ent (entlast))))

    (setq #Obj    (vlax-ename->vla-object #Ent)
          #Length (vla-get-length #Obj)
          #LType  (strcase (vla-get-linetype #Obj))
    ) ;_ setq
    (cond
      ;; 4-2
      ((eq #LType "4-2") (setq #Value (+ (* (fix (/ (- #Length 4) 6)) 6) 4)))
      ;; 1-5
      ((eq #LType "1-5") (setq #Value (+ (* (fix (/ (- #Length 1) 6)) 6) 1)))
      ;; no match
      (T (alert "No matching Linetypes!"))
    ) ;_ cond
    (and #Value
         (vl-cmdf "_.lengthen" "_total" #Value (list #Ent (getvar 'lastpoint)) "")
         (princ (strcat "\nNew Length: " (vl-princ-to-string #Value)))
    ) ;_ and
   )
 ) ;_ cond
 (princ)
) ;_ defun

 

I have it select the end of the line based on the last point picked.

 

I'm heading home, but I'm sure I'll be on later. :)

Posted

Just tried it before I'd better go to bed, looks good to me.

 

I wasn't even close and I've spent hours reading the help files looking for commands I could use....

 

Again many thanks.

Posted
Just tried it before I'd better go to bed, looks good to me.

 

I wasn't even close and I've spent hours reading the help files looking for commands I could use....

 

Again many thanks.

Nah, you were closer than you think. :)

Knowing how to manipulate a command function in real time is kind of tricky the first time.

 

If you are going to have, both a function to draw plines and one to set length of them, I would def. consider a subroutine for the filtering portion, will make life MUCH easier and decrease the amount of code required. Plus, if you update the matching portion, you only have to do it once.

Posted

I will definately split it into subroutines, and also the length formula as the number of line types we are using this on is increasing.

Posted

HI,

 

Hopefully just one more question... ;-)

 

I'm trying to make sure line "type generation" is enabled on the line after it's been drawn. I have added the following to the end of the routine but it doesn't work as it doesn't appear to select the line.

 

Any help would be greatly appreciated.

 

 (vl-cmdf "_.pedit" #Ent "L" "on")

Posted
HI,

 

Hopefully just one more question... ;-)

 

I'm trying to make sure line "type generation" is enabled on the line after it's been drawn. I have added the following to the end of the routine but it doesn't work as it doesn't appear to select the line.

 

Any help would be greatly appreciated.

 

 (vl-cmdf "_.pedit" #Ent "L" "on")

 

Try an extra "". :)

(vl-cmdf "_.pedit" #Ent "_L" "on" "")

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