Rick Posted July 20, 2010 Posted July 20, 2010 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 Quote
dbroada Posted July 21, 2010 Posted July 21, 2010 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. Quote
Rick Posted July 21, 2010 Author Posted July 21, 2010 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...." Quote
10west Posted July 26, 2010 Posted July 26, 2010 '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 Quote
Rick Posted July 27, 2010 Author Posted July 27, 2010 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! Quote
EGoldberg Posted July 28, 2010 Posted July 28, 2010 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 Quote
Rick Posted July 29, 2010 Author Posted July 29, 2010 Thank you sir! Going to see how it works in a few Quote
Recommended Posts
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.