Removing Characters From a String

Removing Characters From a String

timothy_berg
Advocate Advocate
3,739 Views
4 Replies
Message 1 of 5

Removing Characters From a String

timothy_berg
Advocate
Advocate

I'm looking for a way to remove characters from a string for example:

 

N:\Mfg-Design\_MFG Drawings\1420-Drag Conveyors\TEST\00\Model  (remove the underlined text)

 

N:\Mfg-Design\_MFG Drawings\1420-Drag Conveyors\TEST\Export\AutoCad Export\   (add the underlined text)

 

 

0 Likes
Accepted solutions (2)
3,740 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

 

Exactly as you asked for....

 

Google will turn up a lot of good info if you look up VB.net string operations such as Instr, Left, Mid, and Right.

 

oStr = Split("N:\Mfg-Design\_MFG Drawings\1420-Drag Conveyors\TEST\00\Model", "Model")(0)

oNewStr = oStr & "Export\AutoCad Export\ " 

MsgBox(oNewStr)

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 5

timothy_berg
Advocate
Advocate

I pushed the accept instead of the reply sorry for the confusion.  The text before the text that is being modified is not consistent so the rule needs to read its location on my network remove the "Model" location and relocate to the "Export" location. Also I am trying to run this in iLogic not VB.

 

SyntaxEditor Code Snippet

 

Public Sub Main()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\tempDWGOut.ini"
        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    'Set the destination file name
    oDataMedium.FileName = "ENTER FILE LOCATION\Export\AutoCad Export\" & ThisDoc.FileName(False) &".dwg"
    
'    MessageBox.Show("oDataMedium.FileName", "Title")

    
        
    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub


 My goal is to remove the "ENTER FILE LOCATION" so the rule will run without input from the user.

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

As long as the file name only has model in it once, the below code should work just fine. 

 

My first response was also vb.net... which is the same language as iLogic.

 

Just like you don't hop into a car without training first, you shouldn't hop into iLogic without reading the basic documentation on it first either.

 

Public Sub Main()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\tempDWGOut.ini"
        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If
'Set the destination file name oDataMedium.FileName = Split(oDocument.FullFileName, "Model")(0) & "\Export\AutoCad Export\" & ThisDoc.FileName(False) &".dwg" ' MessageBox.Show("oDataMedium.FileName", "Title") 'Publish document. Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End Sub

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 5

cadman777
Advisor
Advisor

Hey Justin,

I just read this looking for how to shorten a string.

Good info!

Then I read this and laughed:

 

Just like you don't hop into a car without training first, you shouldn't hop into iLogic without reading the basic documentation on it first either.

 

Learning how to drive a car is WAY easier then learning how to write code.

Anybody who says otherwise is living in fantasy land!

Let me offer a better and more accurate comparison:

 

Just like you don't hop into a courtroom without training first, you shouldn't hop into iLogic without reading the basic documentation on it first either.

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes