Jump to content

Recommended Posts

Posted

I've searched the forum, and have found several topics on finding and replacing text, but none really fits what I'm trying to do. I have a drawing with a VBA program that asks the user some questions and then the program creates a few part numbers. What I need is some code to put into my command button of "Run Program" where the after the program has put part numbers into the variables, the program will search the drawing for 3 or 4 unique pieces of text, named "rootvalve", "tubenumber", and 'interconnection" and replace those with the part number the program creates. My variables are strings, here are the names of those:

 

PEPartNum will change rootvalve

TubingPartNum changes tubenumber

IEPartNum will change interconnection

 

There is a 100% chance there will be more to add later on, so these three should get me by for now.

 

Thanks in advance!!

 

Rick

Posted

the question often asked in the LISP section is "are you after advice on how to write such a program or are you after somebody to write it for you?" and that question is valid here. I certainly do not have the time to write this but I may have something similar that I can post bits of as you get further with your own offerings.

Posted

Sorry, I thought in my post I had said what I was wanting with the starting of the line "What I need is some code to put into my command button...."

Posted

'Case Sensitive

'1'PEPartNum will change rootvalve

 

testString1 = Trim(ent.textstring)

testText1 = "rootvalve"

NewText1 = "PEPartNum"

 

'2'TubingPartNum changes tubenumber

 

'And so on

 

'3'IEPartNum will change interconnection

 

 

If testString1 = testText1 Then

ent.textstring = Trim(NewText1)

End If

 

'And so on

 

 

'Noncase Sensitive

'1'PEPartNum will change rootvalve

 

testString1 = UCase(Trim(ent.textstring))

testText1 = UCase("rootvalve")

NewText1 = "PEPartNum"

 

'And so on

Posted

Thanks! But I'm getting a error on a vaiable not defined.. Highlighted is the "ent" right after Trim.. I will see if I can fix it!

 

But I sure appreciate it!

Posted

To add to his code above... try this for your for loop.

 

For Each ent In ThisDrawing.ModelSpace ' Check every entity in model space drawing
   If TypeOf ent Is AcadText Or TypeOf ent Is AcadMText Then 'to see if it is Text

' your variable ent will now be set... you can work with 10west's code or use something like the following which is basically his code... 
' if UCASE(trim(ent.textstring)) = 'YOUR ITEM NAME HERE then.... 'do work


   End If ' If ent is txt
Next ' check next entity

Posted

Thank you sir! Going to see how it works in a few

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