Path of the file without the first folder

Path of the file without the first folder

eladm
Collaborator Collaborator
1,426 Views
27 Replies
Message 1 of 28

Path of the file without the first folder

eladm
Collaborator
Collaborator

Hello

 

Can I get help to get a ilogic rule of the file path without the first folder

C:\Work\AAAAA\BBBB

I want to get AAAA\BBBB

to write it in a drawing , to new template and also to old drawings

regards

 

0 Likes
1,427 Views
27 Replies
Replies (27)
Message 2 of 28

TechInventor20
Advocate
Advocate

You mean like this?

 

Dim str As String = "C:\Work\AAAAA\BBBB"
Dim index As Integer = str.IndexOf("\", str.IndexOf("\") + 1)
Dim result As String = Right(str, Len(str)- index)
MsgBox(result)
0 Likes
Message 3 of 28

Michael.Navara
Advisor
Advisor

If the "C:\Work\" represents workspace path of the active project, you can use this

Dim fullFileName As String = ThisDoc.Document.FullFileName
Dim workspacePath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim relativeFileName = fullFileName.Replace(workspacePath, "")
Logger.Debug(relativeFileName)
0 Likes
Message 4 of 28

eladm
Collaborator
Collaborator

the real folder is not aaaa , it was example

I need to get file path without c:\work\ = 8 characters and the use this in a drawing text

0 Likes
Message 5 of 28

eladm
Collaborator
Collaborator

the c:\work\designs\ is the vault workspace 

I need to have the path file of the model (ipt/iam) in the drawing without that

0 Likes
Message 6 of 28

WCrihfield
Mentor
Mentor

Hi @eladm.  There are several ways to get the file system path String (text) without a specific sub-string at the start of it.  What matters is which approach works best for your specific situation.  Do you need to have a "\" symbol left at the start of the remaining text, or not?  You may also want to check if the original String (file path) you have 'StartsWith' the specific text you are looking for, before simply removing 8 characters from the start of it.  That way if the path does not start with that specific text, it will not be removed.

Here is a simple example of using the 'StartsWith' method.

 

Dim oWorkPath As String = "C:\Work\"
Dim oPath As String = "C:\Work\AAAAA\BBBB"
If oPath.StartsWith(oWorkPath) Then
	oPath = oPath.Replace(oWorkPath, "")
End If
MsgBox("oPath = " & oPath,,"")

 

I realize that you still need to put this into a text note on your drawing, but lets get the path string part figured out in a way that suits your needs first.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 28

eladm
Collaborator
Collaborator

folder AAAA and BBBB is not the real folder !!!

just an example

every file have a different path 

0 Likes
Message 8 of 28

JelteDeJong
Mentor
Mentor

what about this:

Dim input As String = "C:\Work\AAAAA\BBBB"

Dim folders = input.Split("\").Skip(2)
Dim newPath = String.Join("\", folders)

MsgBox(newPath)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 9 of 28

TechInventor20
Advocate
Advocate

I know what you'll mean. I get to it tomorrow moarning!

0 Likes
Message 10 of 28

TechInventor20
Advocate
Advocate

This is the rule, I think will work for you. You can change the green number depending on which \ you want to start.

Also you have to put a Ipropertie or a parameter on the drawing where you can put your route in. I did that with a Ipropertie.

 

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
For Each oSheet In oDrawingDoc.Sheets
	oViews = oSheet.DrawingViews
	Dim oView As DrawingView
	For Each oView In oViews
		Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		Dim oFullFilePath As String = oModelDoc.FullFileName
		'MsgBox(oModelDoc.FullFileName)
		dim Input as string = oFullFilePath
		Dim folders = Input.Split("\").Skip(5)
		Dim newPath = String.Join("\", folders)
		'MsgBox(newPath)
		iProperties.Value("Custom", "05-Opmerking") = newPath
	Next
Next
		

  

0 Likes
Message 11 of 28

eladm
Collaborator
Collaborator

 

It's look OK , can you improve the rule , if in a drawing I have couple of sheets - in each one of them different model

So I need for each sheet different iproperties 

regards

0 Likes
Message 12 of 28

TechInventor20
Advocate
Advocate

My knowledge about the drawing api is not that good, but I will look in to it. If @JelteDeJong can look at this problem that would be a win. He knows everything 😉

0 Likes
Message 13 of 28

TechInventor20
Advocate
Advocate

I think I got it. 

Don't know how but it works fine. Just change some of the code in red for the position. You know don't have to have a property or parameter.

Dim oApp = ThisApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
For Each oSheet In oDrawingDoc.Sheets
	oViews = oSheet.DrawingViews
	Dim oView As DrawingView
	For Each oView In oViews
		Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		Dim oFullFilePath As String = oModelDoc.FullFileName
		'MsgBox(oModelDoc.FullFileName)
		Dim Input As String = oFullFilePath
		Dim folders = Input.Split("\").Skip(5)
		Dim newPath = String.Join("\", folders)
		'MsgBox(newPath)
		
    	' Set a reference to the TransientGeometry on active sheet.
    	Dim oTG As TransientGeometry
    	oTG = oApp.TransientGeometry
		
		Dim oNewPosition As Point2d
        'Set reference to the new required position taken and create new 2d point
        oNewPosition = oTG.CreatePoint2d(oView.Center.X, oView.Center.Y - (oView.Height / 2) - 1)
		
'		oSheet.DrawingNotes.GeneralNotes.AddFitted(ThisApplication.TransientGeometry.CreatePoint2d(DrawingView.position.x - DrawingView.width / 2, DrawingView.position.y - DrawingView.height / 2 - 1), newPath)
		oSheet.DrawingNotes.GeneralNotes.AddFitted(oNewPosition,newPath)
		'iProperties.Value("Custom", "05-Opmerking") = newPath
	Next
Next

 

0 Likes
Message 14 of 28

eladm
Collaborator
Collaborator

Hi

 

Thank you , now it don't write to iProperties , I got the text on the drawing sheet , can you add a code that delete the text when rerun the code ? otherwise after run the code at 2nd time we got two texts - the 1st is useless 

0 Likes
Message 15 of 28

TechInventor20
Advocate
Advocate

I was working on that.

 

Dim oApp = ThisApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet

For Each oSheet In oDrawDoc.Sheets For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes
oGeneralNote.Delete
next
next
For Each oSheet In oDrawingDoc.Sheets oViews = oSheet.DrawingViews Dim oView As DrawingView For Each oView In oViews Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oFullFilePath As String = oModelDoc.FullFileName 'MsgBox(oModelDoc.FullFileName) Dim Input As String = oFullFilePath Dim folders = Input.Split("\").Skip(5) Dim newPath = String.Join("\", folders) 'MsgBox(newPath) ' Set a reference to the TransientGeometry on active sheet. Dim oTG As TransientGeometry oTG = oApp.TransientGeometry Dim oNewPosition As Point2d 'Set reference to the new required position taken and create new 2d point oNewPosition = oTG.CreatePoint2d(oView.Center.X, oView.Center.Y - (oView.Height / 2) - 1) ' oSheet.DrawingNotes.GeneralNotes.AddFitted(ThisApplication.TransientGeometry.CreatePoint2d(DrawingView.position.x - DrawingView.width / 2, DrawingView.position.y - DrawingView.height / 2 - 1), newPath) oSheet.DrawingNotes.GeneralNotes.AddFitted(oNewPosition,newPath) 'iProperties.Value("Custom", "05-Opmerking") = newPath Next Next

 

0 Likes
Message 16 of 28

eladm
Collaborator
Collaborator

some error

Error on Line 7 : 'oDrawDoc' is not declared. It may be inaccessible due to its protection level.
Error on Line 7 : End of statement expected.
Error on Line 10 : 'Next' must be preceded by a matching 'For'.

0 Likes
Message 17 of 28

TechInventor20
Advocate
Advocate

Add this instead of the other one

For Each oSheet In oDrawingDoc.Sheets 
For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes
oGeneralNote.Delete
Next
Next
0 Likes
Message 18 of 28

eladm
Collaborator
Collaborator

Hi

 

It look great

can you add this text inside the border or title block?

eladm_0-1661847169683.png

 

because the text can be moved (floating)

When print the drawing i need the path so it need in the bottom corner of the drawing 

0 Likes
Message 19 of 28

TechInventor20
Advocate
Advocate
Dim oApp = ThisApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet

For Each oSheet In oDrawingDoc.Sheets 
For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes 
oGeneralNote.Delete 
Next 
Next

For Each oSheet In oDrawingDoc.Sheets
	oViews = oSheet.DrawingViews
	Dim oView As DrawingView
	For Each oView In oViews
		Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		Dim oFullFilePath As String = oModelDoc.FullFileName
		'MsgBox(oModelDoc.FullFileName)
		Dim Input As String = oFullFilePath
		Dim folders = Input.Split("\").Skip(5)
		Dim newPath = String.Join("\", folders)
		'MsgBox(newPath)
		
    	' Set a reference to the TransientGeometry on active sheet.
    	Dim oTG As TransientGeometry
    	oTG = oApp.TransientGeometry
		
		oBorder = oSheet.Border
		
		Dim oNewPosition As Point2d
		oPlaceX = oBorder.RangeBox.MinPoint.X + 0.1
		oPlaceY = oBorder.RangeBox.MinPoint.Y + 0.25
        'Set reference to the new required position taken and create new 2d point
        oNewPosition = oTG.CreatePoint2d(oPlaceX,oPlaceY)
		
'		oSheet.DrawingNotes.GeneralNotes.AddFitted(ThisApplication.TransientGeometry.CreatePoint2d(DrawingView.position.x - DrawingView.width / 2, DrawingView.position.y - DrawingView.height / 2 - 1), newPath)
		oSheet.DrawingNotes.GeneralNotes.AddFitted(oNewPosition,newPath)
		'iProperties.Value("Custom", "05-Opmerking") = newPath
	Next
Next

 

Change the red to a desired position. if you want it in the right bottom corner change the green text to Max.

0 Likes
Message 20 of 28

eladm
Collaborator
Collaborator

No good , the text is still floating 

the text need to be "inside" the border or title block - this "lock" the text ,

eladm_0-1661849146756.png

 

 

0 Likes