Jump to content

MullinRJ

Member
  • Posts

    2,004
  • Joined

  • Last visited

Posts posted by MullinRJ

  1. 1 hour ago, MarcelP102 said:

    But using ForEachObject and then the  PROCEDURE using this code does not work?

    IF GetRField(h,'ESRI_BGT - wegdeel','functie') = '*voet*'	THEN	SetClass( h, '94 terreinafwerkingen-verharding-trottoir' ); 

     

     

    @MarcelP102,

       Try this instead. 

    IF (Pos( 'voet', GetRField(h, 'ESRI_BGT - wegdeel', 'functie' )) > 0) THEN	
    	SetClass( h, '94 terreinafwerkingen-verharding-trottoir' );

     

    For any occurrence of a substring IN a target_string - (eg. - '*voet*'):

    POS (substring, target_string) > 0

     

    For any occurrence of a substring at the BEGINNING of a target_string - (eg. - 'voet*'):

    POS (substring, target_string) = 1

     

    For any occurrence of a substring at the END of a target_string - (eg. - '*voet'):

    POS (substring, target_string) = (len(target_string) - len(substring) + 1 )

     

    In the last example, make sure the length of the target string is equal to, or longer than, the substring or you could get some false positives.

     

    Raymond

    • Like 2
  2. As usual, @Pat Stanfordbeat me to the punch 😉

     

    Check out this example for reference.

    PROCEDURE xxx;
    VAR
    	H, H1 :Handle;
    	I :Integer;
    	B :Boolean;
    
    BEGIN
          H := FSActLayer;			{ H is a handle to a Polyline }
    
          B := GetNumHoles(H, I);		{ I has the # of holes in the Polyline; and B is TRUE if (H<>nil) - Not very useful. }
    	
          while (I > 0) do begin		{ loop through the holes }
                B := GetHole(H, I, H1);	{ H1 now has a handle to one of the hole objects }
                I := I - 1;
          end;		{ while }
    	
          SysBeep;
    END;
    Run(xxx);

     

    Raymond

    • Like 1
  3. @Sam Jones,

       You have to have VW PREF - Show other objects while in editing mode turned ON before the Greying option will work. It is VW Pref# 14.

     

    So you need a toggle for 

    SetPref(14, not GetPref(14));    { toggle Show others while editing }

     

    and one for

    SetPref(1055, not GetPref(1055));     { toggle Grey others while editing }

     

    Raymond

    • Like 1
  4. Hi @leisure,

       In your example above, your first two lines appear to be syntactically correct, but the rest are not. Originally, I think you had the first two correct.

     

    vs.GetObject('Test_2')
    hDataTag = vs.LNewObj()
    
    should still be:
    
    hDataTag = vs.GetObject('Test_2')

    but this assumes there is a Data Tag on the drawing with the name 'Test_2'. If 'Test_2' is a name to another VW object, you'll get a handle to some other object type. You might want to test the handle you get to ensure it is a PIO instance (type = 86), and that the name of the PIO your handle points to is 'Data Tag'.

     

     

    But, if you are wanting to PLACE a Data Tag, then you need to use:

    hDataTag = vs.CreateCustomObject('Data Tag', X, Y, 0)

    Note vs.CreateCustomObject() returns a handle so you do not need to use vs.LNewObj().

     

     

    and the 5th line returns a boolean, so you might write it like:

    if vs.DT_AssociateWithObj(hDataTag, rec):
    	hDataTag.SetParameter("Roomnumber", "101.01")	# Fill custom object parameters

    assuming the hDataTag.SetParameter() line is syntactically correct, but I doubt Handles have the attribute "SetParameter". If I were to guess, I think you have to access the PIO's record with SetRField() and access the right parameter, but I'm guessing here as I've never played with Data Tags.

     

    HTH,

    Raymond

    • Like 2
  5. Hi @leisure,

       I don't think there was any command in VW 2019 of a similar nature. It is not a command I have ever used, so I don't know if there is another way to make the association. If it is possible, hopefully someone else will chime in with their insight. Or, you could contact Tech Support to see if you can get an answer from VW Engineering.

     

       Yes, there is an online Script Reference at Script Function Reference. It is organized by category (list shown on the right sided of the page), so if you don't know the category of your command, use the Search field at the top of the page to locate it. Also, there is a similar HTML copy that ships with your software, but it is limited to the calls found in you version and older. You can find it in the VW Application folder under /VWHelp/Script Reference/ScriptFunctionReference.html. I usually use the HTML version first, then if I can't find the function, or I think there may be more information available, I check the online version.

     

       At the top of each command in the HTML version, the "Born On Date" is listed to the right of the command name. In the online version, it is listed at the bottom, under the section titled Version. If the function has been deprecated, that "date" is also listed. By "date" I mean VW version.

     

    HTH,

    Raymond

  6. @chrisgeorge292,

       If you are waiting for a specific occurrence in a loop, you can always nest the vs.AlrtDialog() call in an "if" statement. 

     

    You can wait for the loop counter to reach a certain point, say 70:

    for X in range [1, 81]:
    	if X >= 70:
    		vs.AlrtDialog(vs.Concat("I'm here: X= ", X))

     

    or, an object to reach a certain type:

    Hnd = vs.FSActLayer()
    while Hnd != 0:
    	if vs.GetType(Hnd) == 10:		# Text object
    		vs.AlrtDialog(vs.GetText(Hnd))
    	Hnd = vs.NextObj(Hnd)

     

       There are endless ways to configure a test for your stopping point. The filter condition can be simple, or complicated. Often the time you spend crafting a filter will save you stepping through a lot of unnecessary steps, especially if you have to run the code more than once. If it doesn't save you time, then don't do it.

     

    HTH,

    Raymond

  7. Sam,

       The number you're getting is correct, you just have to change the units — from mm to points, AND correct for the layer scale. I thought everybody knew this.  😜

     

    Try:

       LyrScale := GetLScale(GetLayer(PIO_Hand));

       PtSize := GetPrefReal(57)/LyrScale*72/25.4;        { convert doc text size from mm to points }

     

    Raymond

    • Love 1
  8. @leisure,

       I am not sure why vs.DT_AssociateWithObj() is not recognized as it is working on my machine, but there is a problem earlier in your script. vs.RectangleN() does not return a handle. You must get its handle by using vs.LNewObj().
     

    vs.RectangleN ( origin[0], origin[1], direction[0], direction[1], width, height )
    rec = vs.LNewObj()

     

    After you make the above change, if you still get an error with vs.DT_AssociateWithObj() not being recognized, please write back.

     

    Raymond

  9. Hey, Pat.

       I don't think VW put in that feature. I believe it is a Python feature for all strings. This is not a runtime error. The Python engine is flagging a problem before execution, so it is a syntax error.

     

       To look at it another way, how would Python know a string holds a File Pathname? A string is a string is a string, until it is passed to some procedure that tries to use it. It is up to the user to know how to encode strings properly, and not Python's responsibility to know what the user really wants. Basic programming minutiae. The same is true in Pascal when trying to add a single quote to a string, the only difference is Python has more escape characters than Pascal.

     

       What I don't understand, why is "/N" flagged as an error when the Python interpreter is looking for "/n"? Maybe a real Python expert could weigh in on this topic. I know just enough to be dangerous, but not necessarily helpful.

     

    Raymond

  10. 1 hour ago, Pat Stanford said:

    I agree with you. Something like a file name should just be interpreted as a string and accepted directly.

     

    Forgive me, @Pat Stanford. I must now disagree with you; respectfully, of course. I believe Python does document the escape character for newline as "\n", being just one of several. Here is a list of the others – Python string escape characters. Once you know all the rules, it's easier to get it right the first time ... but it does cut down on invigorating forum discussions.

     

    What I don't understand, all of the escape characters use lower case, so why does "\N" kick an error. Also, after playing around with some dummy strings, I found that "\a" doesn't print but does execute, which makes me believe the referenced list may not be complete at least as far as the VW Python engine is concerned. I suggest for anyone that's interested they test every character with a "\" before it to see what happens when a script is run, and when that string is printed.


    Raymond  😉

  11. All I did was ask a question. I made no statement as to the efficacy or prescription of my suggestion. I am just curious if it would work. If I had wanted to spend the time, I would have setup a test file and a dummy script and tried it myself. It's Labor Day, and I'm resting (sort of). I, like many before me, took the lazy way and posed a question rather than launched an investigation. 😜 (Disagree with me again and I shall twice stick my emoji's tongue in your direction)

     

    Happy Labor Day,

    Raymond

     

    PS - I probably could have learned the answer to my query in the time it took me to compose this response.

    • Laugh 1
  12. 28 minutes ago, Pat Stanford said:

    Or my preferred version so that you don't need to use triple quotes. I use the Ascii code for the single quote instead. More characters to type but much easier to see what you have done.  CHR(39) returns a single quote mark.

     

        MyCriteria := Concat('(L=',CHR(39), MyLayer, CHR(39),') & (T=Viewport)');

     

     

    Hey @Pat Stanford,

       Good tip, but while we're on the topics of de-obfuscation and typing conservation, why not elevate the coding experience by declaring a constant to represent a single quote? Particularly in larger scripts, containing multiple formatted strings, I like to use Pascal Constants to represent Tabs, CarriageReturns, and in this case, SingleQuotes. It helps with readability, and faster typing, ... and it's self documenting.

     

       At the beginning of any script define the character constants as needed. This is a short list of my favorites followed by the formatting example:

    PROCEDURE SelectViewport;
    CONST
          Tb = chr(9);	{ TAB character }
          CR = chr(13);	{ Carriage Return character }
          SQ = chr(39);	{ Single Quote character }
    VAR
    ...
    BEGIN
    ...
          MyCriteria := Concat('(L=', SQ, MyLayer, SQ, ') & (T=Viewport)');

     

    Raymond

    • Like 4
  13. Hello @RvG,

    You are close. Your variable MyCriteria is missing two single quotation marks around the Layer Name. The final criteria string should look something like:

        (L='the Active SheetLayer Name') & (T=Viewport).

     

    Here's the Pascal syntax to achieve this.  (I took the liberty of removing unneeded parentheses.) :

        MyCriteria := Concat('(L=''', MyLayer, ''') & (T=Viewport)');
     

    Note, to get a single quote to display in a Pascal String, you need to use two single quotes in a row to represent one literal single quote. So, between the commas in the Concat() statement, the first and last single quotes are string delimiters, and all the single quotes between them should be doubled up (i.e., pairs of single quotes); each pair representing one literal single quote that is part of the string text. It takes some getting used to when you look at it the first time, or the second or third, but eventually it starts to make sense. Python handles this better with two sets of string delimiters to choose from.

     

    Another note: Did you notice the  &  character does not show up in the AlrtDialog() output? It's really in your criteria string, but there be "forces" in the AlrtDialog() call that suppress it. (Ask if you'd like to know the minutiae of WHY.) If you had used Message() instead of AlrtDialog() you would have seen the  &  character.

     

    HTH,

    Raymond

    • Like 2
  14. A few versions ago I had trouble with existing scripts not working on the MAC when I used the backslash "\" delimiter in my $INCLUDE paths. They used to work on both the PC and the MAC. To solve the problem I switched the MAC pathnames to use the colon ":" delimiter. I'm still using colons on the MAC, and like Sam, I use absolute paths. I'm not sure how all of this plays into using relative paths. When I do use a Workgroup folder, colons still work — again, with absolute paths.

     

    Now here's the confusing part (at least for me.) After reading the posts above, I went back to a MAC script with lots of $INCLUDE files and replaced all the colon delimiters with forward slashes "/"  —  it worked.

     

    I then tried the backslash "\"  —  it worked. 

     

    This is in VW 2022, so my take on this issue is I have no idea what is supposed to be used and what is to be avoided. It seems I can again use any of the three delimiters on the MAC. I haven't tried changing anything for scripts on the PC, but that environment still works with the backslash, and has for as long as I have used it, even when the $INCLUDEd files reside on the MAC, so I'm not about to mess with a working object there. 

     

    For me, the beauty of using the backslash for a delimiter was that the same code could be used on the MAC and PC, except for specifying the Volume. After that, the paths were identical. Well, at least things are changing back to being more flexible.

     

    Raymond

  15. Hi @shiori,

       I just tried setting the fill color of a rectangle to 50, 0, 200 using your new script snippet and I get the expected result. When I open the color palette to show Active Document Colors, the last color is the newly created color, and as you can see from the screen shot it is correct. This is using VW 2020 SP6. I also tried it in VW 2022 SP4 and it also works.

     

    image.png.632de34db44841f63d690f0c36e313e8.png

     

     

       I think you are seeing a bug with the RGB Color Picker. It does not report correct values. I see you are on a PC. I am using a MAC, and I see a similar distortion in the RGB numbers when I look at the RGB slider values, and the Spectrum displays.

     

       When you select an object, open the color picker in the Attributes Palette and select the Active Document button (it's the top button at the bottom of the color window). One of the colors will be highlighted which corresponds to your selected object. Hover your cursor over that color swatch and the color values should popup in about a second. Use these values to determine your color.

     

    HTH,

    Raymond

     

    PS - I believe this bug has been reported. If not I'll enter one tomorrow.

     

  16. Try Num2StrF();

    It will format your number to the current document units format. If your document units are not in Ft-In, you will have to set the document units to Feet-Inches temporarily before making the conversion, then set it back when done.

     

    If you need help changing document units, please write back.

     

    Raymond

  17. 1 hour ago, Kevin Allen said:

    My bad, I thought I recalled that ReShaper offered the unrotated dimension of the final object.

     

    Hi, @Kevin Allen.

        Reshaper can report the original dimensions and orientation of a solid, even if it is incorporated in another solid, but you have to enter the outer solid container to query the solid inside. Reshaper will work inside container objects, but it won't do so from the outside of the container. That would be cool if it could, but I'm not that good of a programmer.

     

    Raymond

  18. 45 minutes ago, Bruce Kieffer said:

    I think that is exactly what I want. I believe an object's dimensions should be irrelevant of it's rotation. And when a hole is drilled through it rotated or not it does not change size. I can't imagine any situation where a person would not want the true dimensions of an object.

     

    Hi Bruce,

       Relative to what? Forgive me, but I think you are missing the bigger picture. In your specific case, I know what you want, but to get that you have to perform your operations in an orientation that provides your expected answer. This expectation does not hold for every user.

     

       Here's a proposal; can you define an exact procedural definition of how VW should report values after solid operations? This has to include situations where there are several solids arrayed in a complex assembly of additions and subtractions. In your case you only have one extrude being subtracted from, what if you had two extrudes of different sizes added together at 90° to each other, then you drill a hole through both at once? Would you expect VW to report the initial unrotated dimensions of one of those extrudes after the composite subtraction? If so, which one? Do you see how this can get very complicated very fast? I appreciate the simplicity you are looking for, but I think it only applies to a very small subset of solid operations, and not the general picture. 

     

    Respectfully,

    Raymond

     

×
×
  • Create New...