Sheet Rename

Hi,

I have a drawing with the following sheets and order:
GF, 1F, 2F, 3F, 4F & RF

I then want to rename them by prefixing a sequential number
as follows and separated by “_”
01, 02, 03, 04, 05 & 06

Expected output to read as:
01_GF, 02_1F, 03_2F, 04_3F, 05_4F & 06_RF

Please refer to image below

My problem is DocumentExtensions.GetLayouts is spitting
a sorted result.

Thus my result is 01_1F instead of 01_GF, etc.

Can someone help me with this please?

Thanks.

Regards,
Joel

Hi there,
The layouts probably get sorted based on when they were created. I haven’t worked with Civil3D files in combination with dynamo, so I can’t help you with how you should sort the layouts. However I would like to give you some advice. That node on the top isn’t very parametric, you could replace it with something like this:

1 Like

This might also help: Dynamo Dictionary

1 Like

So it seems like the problem is on the original node’s end since it is not ordering the data in the order of the sheets. Without changing that directly, I would look to use regex and vary my approach depending on how exactly your sheet format scales. Here is a solution for your specific example. Instead of simply appending to the “result” list variable in each step, it will probably be better to create a sublist for each type, sort each sublist, and then combine them all into the final result at the end. But this should get you started with python:

import re

#start with:
sheets = ['1F', '2F', '3F', '4F', 'GF', 'RF']
result = []

#reference only#
#final sheets should be:
final_sheets = ['GF', '1F', '2F', '3F', '4F', 'RF']

#so ordering of sheets should be this and then with numerical prefix 
order = ['GF', 'F', 'RF']
#reference only#

#Identify sheets with the letters 'GF' and adds to result

#regex that looks for the string 'GF'
pattern = '(GF)'

for sheet in sheets:
    if re.search(pattern, sheet):
        result.append(sheet)
    else:
        pass

#Identify sheets with a number prefix and then 'F' letter and adds to result

#regex that looks for the string 'F' with a numeric prefix
pattern = '\d+[F]'
#

for sheet in sheets:
    if re.search(pattern, sheet):
        result.append(sheet)
    else:
        pass

#Identify sheets with the letters 'RF' and adds to result

#regex that looks for the string 'RF'
pattern = '(RF)'

for sheet in sheets:
    if re.search(pattern, sheet):
        result.append(sheet)
    else:
        pass

print(result)

2 Likes

Hi pieter.lamoen,

Thanks for your help. Although i don’t fully understand this but it does the work.

Thanks for your help.

Regards,
Joel

It is shorthand for if-then-else.

l==1 ? “0”+s : s;
if l==1 then “0”+s else s

This means:

if l is equal to 1 (l is the calculated length of the string) then return the string with a prefix zero, else return the string as it is.

4 Likes

It appears that there isn’t a clear way to extract the layouts in the same order as they appear in Civil 3D. I spent some time finding and extracting the paperspace block items that represent the layouts, but they sort alphabetically too. I then took a look at the paperspace block parameters, but didn’t see anything that indicated a position relative to the other blocks/layouts. All that to say, I think we’re only going to get layouts sorted alphabetically…but I’m still a novice, so I could be wrong.

1 Like

Nothing is sorted in AutoCAD, everything is done in the UI there.

Layouts have a taborder property so it is possible to sort, but you need to get the Layout object, not the blockreference.

Edit: there is no taborder node in the Civil3DToolkit, you might do something in Python or wait a while. Soon I will release a package with new nodes, with these it is possible to get the layouts sorted by taborder:

As they are in Civil 3D:

image

6 Likes

Thanks for the clarification. Really appreciate it.

Thanks for the time. Really appreciate it.

Thanks for the time. I’m still novice. Hope i could learn Python too.

Anton, the true hero! Super excited for your package release!

2 Likes

There’s a bunch of new nodes in Camber v3.0.0 that should help with this.

layouts

4 Likes

This looks promising… i will have a look later.

Thank you so much for the help…very much appreciated.

Hi mzjensen,

I finished installing Camber v3.0.0 but i could not access these Layout nodes as shown on your screen shot. Is it because of my C3D version?

image

Thanks ahead.

Regards,
Joel

Yes - you will need to upgrade to a later version of Civil 3D, as per the compatibility note in the release notes here: Releases · mzjensen/Camber · GitHub.

FWIW I would jump straight to 2022.1.1 if you can; no valid reason not to really.

1 Like