Jump to content

Recommended Posts

Posted (edited)

Let me start out by saying that I'm much more fluent in excel VBA than I am in autoCAD vba.

 

I have around 200 drawings in sheet set. Half of the sheet numbers are just numbers and the other half are numbers with a D at the end. I want to add a dash before the D if the sheet number has one. Basically, I need to make this

 

1

1D

2

2D

3

3D

 

look like this

 

1

1-D

2

2-D

3

3-D

 

I wrote something that would do it in excel if it helps but I have no idea how to specify the sheet set or even the sheet number property for each drawing...Here's what I wrote in excel. It's simple and it works great.

 

Public Sub demolition()

For Each cell In Range("E6:E13")

If Right(cell.Text, 1) = "D" Then

cell.Value = Left(cell.Text, Len(cell.Text) - 1)

End If

Next cell


End Sub

Edited by adamsdr3
Posted

Is it text or block attribute? Individual dwg's? all one but different viewports?

 

 

 

 

I'm not sure this will help but...

(setq lst '("1" "1D" "2" "3" "3D" "4"))

(repeat (setq n (length lst))
 (and (wcmatch (strcase (nth (setq n (1- n)) lst)) "*D")
   (setq lst 
     (subst (vl-string-subst "-D" "D" (nth n lst))
       (nth n lst) lst
     )
   )
 )
)

Posted

It is neither text or a block attribute. They are all individual dwg's with different viewports. I basically just need to change the sheet number property within sheetset

Posted

the tab names? or drawing (dwg) names? Forgive my ignorance, I haven't had to deal with sheet sets in 8years

Posted

Each sheet set has subsets (what I think you're callings tabs). Within the subset are the sheets. Each sheet in sheet set has 2 properties; a sheet number and a sheet title. The code that I need to run effects the sheet number.

Posted (edited)

For just the active document.

 

(vlax-for x (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object)))
 (and (setq n (strcase (vla-get-name x)))
   (eq (substr n (setq nl (strlen n)) 1) "D")
   (vla-put-name x (strcat (substr n 1 (1- nl)) "-D"))
 )
)

For multiple dwgs

(vlax-for d (vla-get-documents (vlax-get-acad-object))
 (vlax-for x (vla-get-Layouts d)
   (and (setq n (strcase (vla-get-name x)))
      (eq (substr n (setq nl (strlen n)) 1) "D")
     (vla-put-name x (strcat (substr n 1 (1- nl)) "-D"))
   )
 )
)

Edited by Lt Dan's legs
Cleaning things up
Posted

Thanks for your help. Before I run this on the test sheetset I made, how does it select the sheetset that it runs on? is it the set that is currently active?

Posted

check the gif out. I hope this is what you want (fingers crossed)

GIF.jpg

Posted

I'm honestly completely lost. I read up on how to load a LSP file. I pasted the text into notepad and saved the file with a .LSP extension. then I loaded it into autocad and typed the name into the prompt. here is the result.

 

Sorry. Still new to Lisp http://imgur.com/QCeXiC2

Posted

Dan, the Sheet set is different than layouts though Sheet set can not be modified or in other words AutoLISP have no access to Sheet sets at all.

Posted

I see. See comment #4. lol

 

Thank you for your input, Tharwat. I would've been driving myself crazy over this

Posted

I found the code I need to change the sheet number property, now all I need is a way to loop through them all. In excel, I just defined the cells I need to loop through as a range. Does anyone know if there is a way to do something similar for the sheets in a subset in VBA?

Posted (edited)
I see. See comment #4. lol

Sorry , I have read all OP's replies to get sure if they meant Layout in any other words but couldn't find any, so that's why I wanted to pay your attention to it.

Edited by Tharwat

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