Author Topic: Change Profile View Style via Lisp  (Read 1087 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2544
  • I can't remeber what I already asked! I need help!
Change Profile View Style via Lisp
« on: May 06, 2021, 03:53:07 PM »
I stumbled on this from Jeff M which is supposed to change a profile view style. However, I can not seem to get it to work.

Anyone have any ideas possibly?

Code: [Select]
(vl-load-com)

(defun c:test (/ ent)
(setq Ent (car (entsel "\nSelect Profile View: ")))
  (and (setq *acad* (vlax-get-acad-object))
       (setq C3D (strcat "HKEY_LOCAL_MACHINE\\" (if vlax-user-product-key (vlax-user-product-key) (vlax-product-key) ) )
      C3D (vl-registry-read C3D "Release")
      C3D (substr C3D 1 (vl-string-search "." C3D (+ (vl-string-search "." C3D) 1) ) )
      C3D (vla-getinterfaceobject *acad* (strcat "AeccXUiLand.AeccApplication." C3D) )      )
       (setq C3Ddoc (vla-get-activedocument C3D))
  )
(setq settings (vlax-get c3ddoc 'settings))
(setq pvcmdsettings (vlax-get settings 'profileviewcommandssettings))
(setq createpvsettings (vlax-get pvcmdsettings 'createprofileviewsettings))
(setq stylesettings (vlax-get createpvsettings 'stylesettings))
(vlax-put (vlax-get stylesettings 'style) 'value "Full Grid");;The stylename must exist!!!

(princ))

https://forums.autodesk.com/t5/civil-3d-customization/modify-default-civil-3d-styles-with-lisp/td-p/7173700


Thanks for any help!
Civil3D 2020

Jeff_M

  • King Gator
  • Posts: 4023
  • C3D user & customizer
Re: Change Profile View Style via Lisp
« Reply #1 on: May 06, 2021, 07:30:49 PM »
The code I posted in that link changes the default style used when creating a ProfielView, and works fine It looks like you added the (getent...) line and assumed it should work to change the style?

Jeff_M

  • King Gator
  • Posts: 4023
  • C3D user & customizer
Re: Change Profile View Style via Lisp
« Reply #2 on: May 06, 2021, 07:53:05 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ ent C3D C3DDOC PV PVSTYLES STYLE STYLES)
  2.   (if
  3.     (and
  4.       (setq Ent (entsel "\nSelect Profile View: "))
  5.       (setq *acad* (vlax-get-acad-object))
  6.       (setq C3D (strcat "HKEY_LOCAL_MACHINE\\"
  7.                         (if vlax-user-product-key
  8.                           (vlax-user-product-key)
  9.                           (vlax-product-key)
  10.                         )
  11.                 )
  12.             C3D (vl-registry-read C3D "Release")
  13.             C3D (substr C3D
  14.                         1
  15.                         (vl-string-search
  16.                           "."
  17.                           C3D
  18.                           (+ (vl-string-search "." C3D) 1)
  19.                         )
  20.                 )
  21.             C3D (vla-getinterfaceobject
  22.                   *acad*
  23.                   (strcat "AeccXUiLand.AeccApplication." C3D)
  24.                 )
  25.       )
  26.       (setq C3Ddoc (vla-get-activedocument C3D))
  27.     )
  28.      (progn
  29.        (setq pvstyles (vlax-get c3ddoc 'profileviewstyles))
  30.        (vlax-for itm pvstyles
  31.          (if (= (vlax-get itm 'name) "Full Grid")
  32.            (setq thestyle itm)
  33.          )
  34.        )
  35.        ;; this errored out (setq style (vlax-invoke-method pvstyles 'item "Full Grid"));;The stylename must exist!!!
  36.        (if thestyle
  37.          (progn
  38.            (setq pv (vlax-ename->vla-object (car ent)))
  39.            (vlax-put pv 'style thestyle)
  40.          )
  41.        )
  42.  
  43.  
  44.      )
  45.   )
  46.  
  47.   (princ)
  48. )
  49.  

MSTG007

  • Gator
  • Posts: 2544
  • I can't remeber what I already asked! I need help!
Re: Change Profile View Style via Lisp
« Reply #3 on: May 07, 2021, 07:52:46 AM »
Thank you for saving the day! lol. It works just like it needs to to switch the selected profile view style!

This sounds alittle crazy, but I am trying to see if i can create a toggle with this. Basically, I want to select the profile view I want to work in, then do some hatching commands, by picking areas, Then once I am done, change the profile view style back to the original.

So to get this to somewhat work, I came up with something like this..

Code: [Select]
(defun C:Test ()
(C:test1) ;;Select the profile view to change the style without the grid
(command" "-layer" "OFF" "C-STRC-LABL,C-PIPE-LABL,C-PROF-LABL" "")
(command "-bhatch" "p" "ansi31" "30" "0" pause "")
(command" "-layer" "ON" "C-STRC-LABL,C-PIPE-LABL,C-PROF-LABL" "")
(C:test2) ;;Select the profile view to change the style back to the grid
(princ))
« Last Edit: May 07, 2021, 08:21:37 AM by MSTG007 »
Civil3D 2020