- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Path of the file without the first folder
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
folder AAAA and BBBB is not the real folder !!!
just an example
every file have a different path
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hן
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Add this instead of the other one
For Each oSheet In oDrawingDoc.Sheets
For Each oGeneralNote In oSheet.DrawingNotes.GeneralNotes
oGeneralNote.Delete
Next
Next
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
It look great
can you add this text inside the border or title block?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
No good , the text is still floating
the text need to be "inside" the border or title block - this "lock" the text ,